ImageDetailBigView.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. //
  2. // ImageDetailBigView.m
  3. // 乐销
  4. //
  5. // Created by 隋林栋 on 2017/3/14.
  6. // Copyright © 2017年 ping. All rights reserved.
  7. //
  8. #import "ImageDetailBigView.h"
  9. #import "BaseImage.h"//image
  10. @interface ImageDetailBigView()
  11. {
  12. CGFloat contentSetY;
  13. }
  14. @property (nonatomic, strong) UpImageDetailImageViewCell *cellShow;
  15. @property (nonatomic, strong) UIControl *btnEdit;
  16. @property (nonatomic, strong) UIControl *btnDelete;
  17. @end
  18. @implementation ImageDetailBigView
  19. #pragma mark lazy init
  20. - (NSMutableArray *)aryDatas{
  21. if (!_aryDatas) {
  22. _aryDatas = [NSMutableArray new];
  23. }
  24. return _aryDatas;
  25. }
  26. - (UICollectionView *)collectionImageDetail{
  27. if (_collectionImageDetail == nil) {
  28. //布局
  29. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  30. layout.minimumInteritemSpacing = 0;
  31. layout.minimumLineSpacing = 0;
  32. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  33. CGSize size = [UpImageDetailImageViewCell fetchHeight];
  34. layout.itemSize = size;
  35. //设定滚动方向
  36. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  37. // 6.创建UICollectionView
  38. _collectionImageDetail = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) collectionViewLayout:layout];
  39. // 7.设置collectionImageDetail的背景色
  40. _collectionImageDetail.backgroundColor = [UIColor clearColor];
  41. // 8.设置代理
  42. _collectionImageDetail.collectionViewLayout = layout;
  43. _collectionImageDetail.delegate = self;
  44. _collectionImageDetail.dataSource = self;
  45. _collectionImageDetail.scrollEnabled = YES;
  46. _collectionImageDetail.pagingEnabled = true;
  47. _collectionImageDetail.showsVerticalScrollIndicator = false;
  48. _collectionImageDetail.showsHorizontalScrollIndicator = false;
  49. [_collectionImageDetail registerClass:[UpImageDetailImageViewCell class] forCellWithReuseIdentifier:@"UpImageDetailImageViewCell"];
  50. }
  51. return _collectionImageDetail;
  52. }
  53. - (BaseNavView *)navView{
  54. if (!_navView) {
  55. WEAKSELF
  56. _navView = [BaseNavView initNavTitle:@"" leftImageName:@"left_blue" leftBlock:^{
  57. [weakSelf removeSelf:YES];
  58. } rightImageName:nil righBlock:nil];
  59. [_navView removeSubViewWithTag:TAG_LINE];
  60. _navView.labelTitle.textColor = [UIColor whiteColor];
  61. _navView.backgroundColor = COLOR_BLACK_ALPHA_PER60;
  62. [_navView addSubview:self.btnDelete];
  63. [_navView addSubview:self.btnEdit];
  64. }
  65. return _navView;
  66. }
  67. - (UIControl *)btnEdit{
  68. if (!_btnEdit) {
  69. _btnEdit = [UIControl new];
  70. _btnEdit.tag = 1;
  71. [BaseNavView resetControl:_btnEdit imageName:@"pic_edit" isLeft:false];
  72. _btnEdit.right = self.btnDelete.left;
  73. [_btnEdit addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  74. }
  75. return _btnEdit;
  76. }
  77. - (UIControl *)btnDelete{
  78. if (!_btnDelete) {
  79. _btnDelete = [UIControl new];
  80. _btnDelete.tag = 2;
  81. _btnDelete.width = W(45);
  82. _btnDelete.frame = CGRectMake(SCREEN_WIDTH - _btnDelete.width, STATUSBAR_HEIGHT, _btnDelete.width, NAVIGATIONBAR_HEIGHT - STATUSBAR_HEIGHT);
  83. [_btnDelete addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  84. [_btnDelete addSubview: ^(){
  85. UIImageView * iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pic_del"]];
  86. iv.backgroundColor = [UIColor clearColor];
  87. iv.right = _btnDelete.width - W(15);
  88. iv.centerY = _btnDelete.height/2.0;
  89. return iv;
  90. }()];
  91. }
  92. return _btnDelete;
  93. }
  94. - (PlaceHolderTextView *)label{
  95. if (_label == nil) {
  96. _label = [PlaceHolderTextView new];
  97. _label.backgroundColor = [UIColor clearColor];
  98. _label.textColor = [UIColor whiteColor];
  99. _label.font = [UIFont systemFontOfSize:F(14)];
  100. _label.textContainerInset = UIEdgeInsetsMake(0,0,0,0);
  101. _label.editable = NO;
  102. _label.selectable = NO;
  103. _label.delegate = self;
  104. _label.lineSpace = W(5);
  105. }
  106. return _label;
  107. }
  108. - (UIScrollView *)viewBG{
  109. if (_viewBG == nil) {
  110. _viewBG = [UIScrollView new];
  111. _viewBG.backgroundColor = COLOR_BLACK_ALPHA_PER60;
  112. }
  113. return _viewBG;
  114. }
  115. #pragma mark init
  116. - (instancetype)initWithFrame:(CGRect)frame{
  117. self = [super initWithFrame:frame];
  118. if (self) {
  119. self.widthHeight = XY(SCREEN_WIDTH, SCREEN_HEIGHT);
  120. self.backgroundColor = [UIColor blackColor];
  121. [self addSubview:self.collectionImageDetail];
  122. // [self addSubview:self.navView];
  123. [self addSubview:self.viewBG];
  124. [self.viewBG addSubview:self.label];
  125. }
  126. return self;
  127. }
  128. //reset view
  129. - (void)resetView:(NSMutableArray *)ary isEdit:(BOOL)isEdit index:(NSInteger)index{
  130. self.aryDatas = ary;
  131. self.isEdit = isEdit;
  132. self.btnDelete.hidden = !self.isEdit;
  133. self.btnEdit.hidden = !(self.isEdit && self.blockEdit);
  134. WEAKSELF
  135. [self.collectionImageDetail performBatchUpdates:^{
  136. [weakSelf.collectionImageDetail reloadData];
  137. } completion:^(BOOL finished) {
  138. if (finished) {
  139. [weakSelf.collectionImageDetail performBatchUpdates:^{
  140. [weakSelf.collectionImageDetail scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:index < weakSelf.aryDatas.count?index:0 inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
  141. } completion:^(BOOL finished) {
  142. //初始化显示cell
  143. [weakSelf resetTableCell];
  144. [weakSelf resetNavTitle];
  145. }];
  146. }
  147. }];
  148. }
  149. #pragma mark删除当前图片
  150. - (void)removeItemNow{
  151. int index = 0;
  152. // 获取已经滚动的比例
  153. double ratio = self.collectionImageDetail.contentOffset.x / SCREEN_WIDTH;
  154. int page = floor(ratio + 0.5);
  155. index = page;
  156. if (self.aryDatas.count > index) {
  157. [self.aryDatas removeObjectAtIndex:index];
  158. NSIndexPath * indexPath = [NSIndexPath indexPathForItem:page inSection:0];
  159. if (self.blockRefresh) {
  160. self.blockRefresh();
  161. }
  162. [self.collectionImageDetail deleteItemsAtIndexPaths:@[indexPath]];
  163. if (self.aryDatas.count == 0) {
  164. [self removeSelf:NO];
  165. return;
  166. }
  167. // [self.navView changeTitle:[NSString stringWithFormat:@"%ld/%ld",MIN(page+1, self.aryDatas.count),self.aryDatas.count]];
  168. [self resetviewBG:(int)MIN(page, self.aryDatas.count-1)];
  169. }
  170. }
  171. #pragma mark reset label
  172. - (void)resetNavTitle{
  173. // 获取已经滚动的比例
  174. double ratio = self.collectionImageDetail .contentOffset.x / SCREEN_WIDTH;
  175. int page = (int)(ratio + 0.5);
  176. // [self.navView changeTitle:[NSString stringWithFormat:@"%d/%ld",page+1,self.aryDatas.count]];
  177. [self resetviewBG:page];
  178. }
  179. -(void)resetviewBG:(int)page{
  180. ModelImage *model = self.aryDatas[page];
  181. NSString * pageStr = [NSString stringWithFormat:@" %@",[NSString stringWithFormat:@"%d/%ld",page+1,self.aryDatas.count]];
  182. NSString * str = [NSString stringWithFormat:@"%@ %@",pageStr,UnPackStr(model.desc)];
  183. self.label.leftTop = XY(W(10),W(20));
  184. CGFloat textHeight = [str fetchHeightWidthLimint:SCREEN_WIDTH - W(40) fontNum:F(14) lineSpace:W(5)];
  185. if (textHeight>W(130)) {
  186. self.label.widthHeight = XY(SCREEN_WIDTH - W(20), W(130));
  187. }else{
  188. self.label.widthHeight = XY(SCREEN_WIDTH - W(20), textHeight+W(5));
  189. }
  190. self.label.attributedText = [self setAttributedWith:str rangeStr:pageStr];
  191. contentSetY =self.label.contentSize.height;
  192. self.viewBG.widthHeight = XY(SCREEN_WIDTH, self.label.height + W(60));
  193. self.viewBG.leftBottom = XY(0, self.bottom);
  194. self.label.hidden=self.isHide;
  195. }
  196. -(NSMutableAttributedString *)setAttributedWith:(NSString *)string rangeStr:(NSString *)rangeStr{
  197. NSRange range = [string rangeOfString:rangeStr];
  198. NSValue * value = [NSValue valueWithRange:range];
  199. NSMutableArray * array = [[NSMutableArray alloc] initWithObjects:value, nil];
  200. NSMutableAttributedString * attributed = [ReturnAttributeStr returnDifferentFontWithText:string bigFont:F(18) smallFont:F(14) rangeArray:array];
  201. NSMutableParagraphStyle * detailParagtaphStyle = [[NSMutableParagraphStyle alloc]init];
  202. detailParagtaphStyle.lineSpacing = W(5); //行间距
  203. NSDictionary * detaiDic = @{NSParagraphStyleAttributeName : detailParagtaphStyle,
  204. NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleNone],NSForegroundColorAttributeName : [UIColor whiteColor]};
  205. [attributed addAttributes:detaiDic range:NSMakeRange(0, attributed.length)];
  206. NSShadow *shadow = [[NSShadow alloc]init];
  207. shadow.shadowBlurRadius = 1.0;
  208. shadow.shadowOffset = CGSizeMake(0, 1);
  209. shadow.shadowColor = [UIColor blackColor];
  210. [attributed addAttribute:NSShadowAttributeName
  211. value:shadow
  212. range:NSMakeRange(0, attributed.length)];
  213. return attributed;
  214. }
  215. #pragma mark amplify image
  216. - (void)amplifyImage:(UIImageView *)ivOrigin viewShow:(UIView *)viewShow{
  217. UIImage *image = ivOrigin.image;
  218. UIWindow *window = [UIApplication sharedApplication].keyWindow;
  219. [window endEditing:true];
  220. //背景
  221. UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  222. //获取位置
  223. CGRect oldframe = [ivOrigin convertRect:ivOrigin.bounds toView:window];
  224. [backgroundView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0]];
  225. UIImageView *imageView = [[UIImageView alloc] initWithFrame:oldframe];
  226. [imageView setImage:image];
  227. [backgroundView addSubview:imageView];
  228. [window addSubview:backgroundView];
  229. //动画放大
  230. [UIView animateWithDuration:0.4 animations:^{
  231. CGFloat width,height;
  232. if (image.size.height/image.size.width>SCREEN_HEIGHT/SCREEN_WIDTH) {
  233. width = image.size.width * SCREEN_HEIGHT / image.size.height;
  234. height = SCREEN_HEIGHT;
  235. }else{
  236. //宽度
  237. width = SCREEN_WIDTH;
  238. //高度
  239. height = image.size.height * SCREEN_WIDTH / image.size.width;
  240. }
  241. imageView.widthHeight = XY(width, height);
  242. imageView.center = backgroundView.center;
  243. [backgroundView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1]];
  244. } completion:^(BOOL finished) {
  245. [backgroundView removeFromSuperview];
  246. [viewShow addSubview:self];
  247. self.navView.alpha = 0;
  248. self.label.alpha = 0;
  249. [UIView animateWithDuration:0.2 animations:^{
  250. self.navView.alpha = 1;
  251. self.label.alpha = 1;
  252. }];
  253. }];
  254. }
  255. #pragma mark 显示与隐藏
  256. - (void)showInView:(UIView *)view imageViewShow:(UIImageView *)iv{
  257. [self amplifyImage:iv viewShow:view];
  258. //change status bar
  259. [GlobalMethod exchangeStatusBar:UIStatusBarStyleLightContent];
  260. }
  261. - (void)removeSelf:(BOOL)isNavLeft{
  262. //change status bar
  263. [GlobalMethod exchangeStatusBar:UIStatusBarStyleLightContent];
  264. if (isNavLeft) {
  265. [UIView animateWithDuration:0.3 animations:^{
  266. self.frame = CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
  267. } completion:^(BOOL finished) {
  268. [self removeFromSuperview];
  269. }];
  270. }else{
  271. [self removeFromSuperview];
  272. }
  273. }
  274. #pragma mark - UICollectionView数据源方法
  275. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  276. {
  277. return self.aryDatas.count;
  278. }
  279. // item
  280. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  281. {
  282. UpImageDetailImageViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"UpImageDetailImageViewCell" forIndexPath:indexPath];
  283. cell.detailBigView= self;
  284. cell.navView = self.navView;
  285. cell.viewBG = self.viewBG;
  286. WEAKSELF
  287. cell.blockClick = ^{
  288. [weakSelf removeSelf:NO];
  289. };
  290. cell.hidenBlockClick = ^{
  291. weakSelf.navView.hidden = !weakSelf.navView.hidden;
  292. weakSelf.viewBG.hidden = !weakSelf.viewBG.hidden;
  293. };
  294. [cell resetWithModel:self.aryDatas[indexPath.row] isEdit:self.isEdit];
  295. return cell;
  296. }
  297. -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
  298. CGFloat offsetY = scrollView.contentOffset.y;
  299. if (scrollView == self.label) {
  300. if (self.label.height>=W(130)) {
  301. if ((self.label.height<W(170)&& offsetY>0) ||offsetY<0 ) {
  302. self.label.leftTop = XY(W(10),W(20));
  303. self.label.widthHeight = XY(SCREEN_WIDTH - W(20), self.label.height+offsetY);
  304. if (offsetY<0 && self.label.height<W(130)) {
  305. self.label.widthHeight = XY(SCREEN_WIDTH - W(20), W(130));
  306. }
  307. if (offsetY>0 && self.label.height>W(170) ) {
  308. self.label.widthHeight = XY(SCREEN_WIDTH - W(20), W(170));
  309. }
  310. if (offsetY>0 && self.label.height>=contentSetY) {
  311. self.label.widthHeight = XY(SCREEN_WIDTH - W(20),contentSetY-1);
  312. }
  313. self.viewBG.widthHeight = XY(SCREEN_WIDTH, self.label.height+W(60));
  314. self.viewBG.leftBottom = XY(0, self.bottom);
  315. scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0);
  316. }
  317. }
  318. }
  319. }
  320. #pragma mark scroll delegate
  321. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
  322. if (scrollView !=self.label) {
  323. [self resetNavTitle];
  324. [self resetTableCell];
  325. }
  326. }
  327. - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
  328. if (!decelerate && scrollView !=self.label) {
  329. [self resetNavTitle];
  330. [self resetTableCell];
  331. }
  332. }
  333. #pragma mark reset tableview cell visible
  334. - (void)resetTableCell{
  335. NSIndexPath * indexPath = [self.collectionImageDetail indexPathsForVisibleItems].lastObject;
  336. UpImageDetailImageViewCell * cellNow = (UpImageDetailImageViewCell *)[self.collectionImageDetail cellForItemAtIndexPath:indexPath];
  337. if (cellNow && cellNow != self.cellShow) {
  338. if ([self.cellShow isKindOfClass:UpImageDetailImageViewCell.class]) {
  339. [self.cellShow recoverScrollView];
  340. }
  341. self.cellShow = cellNow;
  342. }
  343. }
  344. #pragma mark 点击事件
  345. - (void)btnClick:(UIButton *)sender{
  346. WEAKSELF
  347. switch (sender.tag) {
  348. case 1://edit
  349. {
  350. if (self.blockEdit) {
  351. self.blockEdit();
  352. }
  353. [self removeSelf:NO];
  354. }
  355. break;
  356. case 2://delete
  357. {
  358. ModelBtn * modelDismiss = [ModelBtn modelWithTitle:@"取消" imageName:nil highImageName:nil tag:TAG_LINE color:[UIColor redColor]];
  359. ModelBtn * modelConfirm = [ModelBtn modelWithTitle:@"确认" imageName:nil highImageName:nil tag:TAG_LINE color:COLOR_BLUE];
  360. modelConfirm.blockClick = ^(void){
  361. [weakSelf removeItemNow];
  362. };
  363. [BaseAlertView initWithTitle:@"确认删除?" content:@"确认删除当前图片" aryBtnModels:@[modelDismiss,modelConfirm] viewShow:self];
  364. }
  365. break;
  366. default:
  367. break;
  368. }
  369. }
  370. @end
  371. @implementation UpImageDetailImageViewCell
  372. #pragma mark 懒加载
  373. - (UIImageView *)iv{
  374. if (_iv == nil) {
  375. _iv = [UIImageView new];
  376. _iv.backgroundColor = [UIColor clearColor];
  377. _iv.widthHeight = XY(SCREEN_WIDTH,SCREEN_HEIGHT);
  378. _iv.contentMode = UIViewContentModeScaleAspectFit;
  379. _iv.userInteractionEnabled = true;
  380. [_iv addTarget:self action:@selector(imageClick)];
  381. UILongPressGestureRecognizer*longTap = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(imglongTapClick:)];
  382. [_iv addGestureRecognizer:longTap];
  383. }
  384. return _iv;
  385. }
  386. - (UIScrollView *)scBG{
  387. if (!_scBG) {
  388. _scBG = [UIScrollView new];
  389. _scBG.scrollEnabled = true;
  390. _scBG.delegate = self;
  391. _scBG.maximumZoomScale = 2;
  392. _scBG.backgroundColor = [UIColor clearColor];
  393. _scBG.showsVerticalScrollIndicator = false;
  394. _scBG.showsHorizontalScrollIndicator = false;
  395. if (@available(iOS 11.0, *)) {
  396. _scBG.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  397. }
  398. _scBG.decelerationRate = 0.1f;
  399. [_scBG.panGestureRecognizer addTarget:self action:@selector(scrollViewPanMethod:)];
  400. _scBG.userInteractionEnabled = true;
  401. }
  402. return _scBG;
  403. }
  404. #pragma mark 获取高度
  405. + (CGSize)fetchHeight{
  406. return CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT );
  407. }
  408. #pragma mark 初始化
  409. - (instancetype)initWithFrame:(CGRect)frame{
  410. self = [super initWithFrame:frame];
  411. if (self) {
  412. self.backgroundColor = [UIColor clearColor];
  413. self.contentView.backgroundColor = [UIColor clearColor];
  414. [self addSubView];
  415. }
  416. return self;
  417. }
  418. //添加subview
  419. - (void)addSubView{
  420. [self.contentView addSubview:self.scBG];
  421. [self.scBG addSubview:self.iv];
  422. }
  423. #pragma mark 刷新view
  424. - (void)resetWithModel:(ModelImage *)model isEdit:(BOOL)isEdit{
  425. [self removeSubViewWithTag:TAG_LINE];//移除线
  426. //刷新view
  427. [self.iv sd_setImageWithModel:model placeholderImageName:IMAGE_BIG_DEFAULT];
  428. self.iv.leftTop = XY(0, 0);
  429. self.iv.widthHeight = XY(SCREEN_WIDTH,SCREEN_HEIGHT);
  430. [self recoverScrollView];
  431. }
  432. //recover scroll view
  433. - (void)recoverScrollView{
  434. [self.scBG setZoomScale:1 animated:false];
  435. self.scBG.leftTop = XY(0, 0);
  436. self.scBG.widthHeight = XY(SCREEN_WIDTH,SCREEN_HEIGHT);
  437. self.scBG.contentSize = CGSizeMake(SCREEN_WIDTH, 2*SCREEN_HEIGHT);
  438. }
  439. #pragma mark click
  440. - (void)imageClick{
  441. WEAKSELF
  442. [UIView animateWithDuration:0.35 animations:^{
  443. //设置移除动画
  444. CGFloat transformHeight =SCREEN_HEIGHT;
  445. if (weakSelf.scBG.contentOffset.y>0) {
  446. transformHeight = -transformHeight;
  447. }
  448. self.scBG.transform = CGAffineTransformTranslate(self.scBG.transform, self.scBG.contentOffset.x,transformHeight);
  449. self.detailBigView.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
  450. }completion:^(BOOL finished) {
  451. if (self.blockClick) {
  452. self.blockClick();
  453. }
  454. [self recoverScrollView];
  455. weakSelf.scBG.contentInset = UIEdgeInsetsZero;
  456. }];
  457. if (self.hidenBlockClick) {
  458. self.hidenBlockClick();
  459. }
  460. }
  461. #pragma mark - 长按手势方法
  462. -(void)imglongTapClick:(UIGestureRecognizer *)gesture{
  463. if(gesture.state==UIGestureRecognizerStateBegan)
  464. {
  465. WEAKSELF
  466. [GlobalMethod fetchPhotoAuthorityBlock:^{
  467. [BaseAlertView customAlertControllerWithTitle:@"保存图片" modelBtnArr:@[[ModelBtn modelWithTitle:@"保存图片到手机" imageName:nil highImageName:nil tag:1 color:COLOR_LABEL]] cancelTitle:@"取消" cancelColor:COLOR_LABEL selectIndex:^(int selectIndex) {
  468. if (selectIndex==1) {
  469. UIImageWriteToSavedPhotosAlbum(weakSelf.iv.image,weakSelf,@selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:),nil);
  470. }
  471. }];
  472. }];
  473. }
  474. }
  475. - (void)imageSavedToPhotosAlbum:(UIImage*)image didFinishSavingWithError: (NSError*)error contextInfo:(void*)contextInfo{
  476. NSString*message =@"";
  477. if(!error) {
  478. message =@"成功保存到相册";
  479. }else
  480. {
  481. message = [error description];
  482. }
  483. NSString * str = message;
  484. NSString * cancelButtonTitle = NSLocalizedString(@"确定", nil);
  485. NSString * destructiveButtonTitle = NSLocalizedString(str, nil);
  486. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleAlert];
  487. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  488. //NSLog(@"取消");
  489. }];
  490. UIAlertAction *destructiveAction = [UIAlertAction actionWithTitle:destructiveButtonTitle style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action){
  491. }];
  492. [alertController addAction:destructiveAction];
  493. [alertController addAction:cancelAction];
  494. [GB_Nav presentViewController:alertController animated:YES completion:nil];
  495. }
  496. - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
  497. {
  498. if (scale != 1) {return;}
  499. [self recoverScrollView];
  500. }
  501. -(void)scrollViewPanMethod:(UIPanGestureRecognizer *)pan{
  502. if (_scBG.zoomScale != 1.0f) {return;}
  503. CGFloat contentOffSetY = _scBG.contentOffset.y > 0 ? -_scBG.contentOffset.y:_scBG.contentOffset.y;
  504. //拖拽结束后判断位置
  505. WEAKSELF
  506. if (pan.state == UIGestureRecognizerStateEnded) {
  507. if (ABS(_scBG.contentOffset.y) < 120.0f) {
  508. [UIView animateWithDuration:0.35 animations:^{
  509. self.navView.alpha = 1;
  510. self.viewBG.alpha = 1;
  511. self.detailBigView.backgroundColor = [UIColor colorWithWhite:0 alpha:1];
  512. weakSelf.scBG.contentOffset = CGPointZero;
  513. weakSelf.scBG.contentInset = UIEdgeInsetsZero;
  514. [self recoverScrollView];
  515. }completion:^(BOOL finished) {
  516. weakSelf.scBG.contentOffset = CGPointZero;
  517. weakSelf.scBG.contentInset = UIEdgeInsetsZero;
  518. }];
  519. }else{
  520. [UIView animateWithDuration:0.35 animations:^{
  521. //设置移除动画
  522. CGFloat transformHeight =SCREEN_HEIGHT;
  523. if (weakSelf.scBG.contentOffset.y>0) {
  524. transformHeight = -transformHeight;
  525. }
  526. self.scBG.transform = CGAffineTransformTranslate(self.scBG.transform, self.scBG.contentOffset.x,transformHeight);
  527. self.detailBigView.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
  528. }completion:^(BOOL finished) {
  529. if (self.blockClick) {
  530. self.blockClick();
  531. }
  532. [self recoverScrollView];
  533. weakSelf.scBG.contentInset = UIEdgeInsetsZero;
  534. }];
  535. }
  536. }else{
  537. //拖拽过程中逐渐改变透明度
  538. _scBG.contentInset = UIEdgeInsetsMake(-contentOffSetY, 0, 0, 0);
  539. CGFloat alpha = 1 - 8*ABS(_scBG.contentOffset.y/(_scBG.bounds.size.height));
  540. self.navView.alpha = alpha;
  541. self.viewBG.alpha = alpha;
  542. self.detailBigView.backgroundColor = [UIColor colorWithWhite:0 alpha:alpha];
  543. }
  544. }
  545. #pragma mark scroll delegate
  546. -(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
  547. {
  548. return self.iv;
  549. }
  550. @end