DKPhotoPickerBrowserViewController.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. //
  2. // ZLPhotoPickerBrowserViewController.m
  3. // ZLAssetsPickerDemo
  4. //
  5. //
  6. #import <AssetsLibrary/AssetsLibrary.h>
  7. #import <objc/runtime.h>
  8. #import "DKPhotoPickerBrowserViewController.h"
  9. #import "DKPhotoPickerBrowserPhoto.h"
  10. #import "DKPhotoPickerDatas.h"
  11. #import "UIView+Extension.h"
  12. #import "DKPhotoPickerBrowserPhotoScrollView.h"
  13. #import "DKPhotoPickerCommon.h"
  14. #import "DKAnimationScrollView.h"
  15. static NSString *_cellIdentifier = @"collectionViewCell";
  16. @interface DKPhotoPickerBrowserViewController () <UIScrollViewDelegate,DKPhotoPickerPhotoScrollViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,UICollectionViewDelegate>
  17. // 控件
  18. @property (weak,nonatomic) UILabel *pageLabel;
  19. @property (weak,nonatomic) UIButton *deleleBtn;
  20. @property (weak,nonatomic) UIButton *backBtn;
  21. @property (weak,nonatomic) UICollectionView *collectionView;
  22. // 数据相关
  23. // 单击时执行销毁的block
  24. @property (nonatomic , copy) DKPickerBrowserViewControllerTapDisMissBlock disMissBlock;
  25. // 装着所有的图片模型
  26. @property (nonatomic , strong) NSMutableArray *photos;
  27. // 当前提供的分页数
  28. @property (nonatomic , assign) NSInteger currentPage;
  29. @end
  30. @implementation DKPhotoPickerBrowserViewController
  31. #pragma mark - getter
  32. #pragma mark photos
  33. - (NSMutableArray *)photos{
  34. if (!_photos) {
  35. _photos = [NSMutableArray array];
  36. [_photos addObjectsFromArray:[self getPhotos]];
  37. }
  38. return _photos;
  39. }
  40. #pragma mark collectionView
  41. - (UICollectionView *)collectionView{
  42. if (!_collectionView) {
  43. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  44. flowLayout.minimumLineSpacing = ZLPickerColletionViewPadding;
  45. flowLayout.itemSize = self.view.size;
  46. flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  47. UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.width + ZLPickerColletionViewPadding,self.view.height) collectionViewLayout:flowLayout];
  48. collectionView.showsHorizontalScrollIndicator = NO;
  49. collectionView.showsVerticalScrollIndicator = NO;
  50. collectionView.pagingEnabled = YES;
  51. collectionView.backgroundColor = [UIColor clearColor];
  52. collectionView.bounces = YES;
  53. collectionView.delegate = self;
  54. [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:_cellIdentifier];
  55. [self.view addSubview:collectionView];
  56. self.collectionView = collectionView;
  57. _collectionView.translatesAutoresizingMaskIntoConstraints = NO;
  58. [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[_collectionView]-x-|" options:0 metrics:@{@"x":@(-20)} views:@{@"_collectionView":_collectionView}]];
  59. [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[_collectionView]-0-|" options:0 metrics:nil views:@{@"_collectionView":_collectionView}]];
  60. self.pageLabel.hidden = NO;
  61. self.deleleBtn.hidden = !self.isEditing;
  62. }
  63. return _collectionView;
  64. }
  65. #pragma mark deleleBtn
  66. - (UIButton *)deleleBtn{
  67. if (!_deleleBtn) {
  68. UIButton *deleleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  69. deleleBtn.translatesAutoresizingMaskIntoConstraints = NO;
  70. deleleBtn.titleLabel.font = [UIFont systemFontOfSize:15];
  71. // [deleleBtn setTitle:@"删除" forState:UIControlStateNormal];
  72. [deleleBtn setImage:[UIImage imageNamed:@"nav_delete_btn"] forState:UIControlStateNormal];
  73. // 设置阴影
  74. deleleBtn.layer.shadowColor = [UIColor blackColor].CGColor;
  75. deleleBtn.layer.shadowOffset = CGSizeMake(0, 0);
  76. deleleBtn.layer.shadowRadius = 3;
  77. deleleBtn.layer.shadowOpacity = 1.0;
  78. [deleleBtn addTarget:self action:@selector(delete) forControlEvents:UIControlEventTouchUpInside];
  79. [self.view addSubview:deleleBtn];
  80. self.deleleBtn = deleleBtn;
  81. NSString *widthVfl = @"H:[deleleBtn(deleteBtnWH)]-margin-|";
  82. NSString *heightVfl = @"V:|-margin-[deleleBtn(deleteBtnWH)]";
  83. NSDictionary *metrics = @{@"deleteBtnWH":@(50),@"margin":@(10)};
  84. NSDictionary *views = NSDictionaryOfVariableBindings(deleleBtn);
  85. [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:widthVfl options:0 metrics:metrics views:views]];
  86. [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:heightVfl options:0 metrics:metrics views:views]];
  87. }
  88. return _deleleBtn;
  89. }
  90. #pragma mark pageLabel
  91. - (UILabel *)pageLabel{
  92. if (!_pageLabel) {
  93. UILabel *pageLabel = [[UILabel alloc] init];
  94. pageLabel.font = [UIFont systemFontOfSize:18];
  95. pageLabel.textAlignment = NSTextAlignmentCenter;
  96. pageLabel.userInteractionEnabled = NO;
  97. pageLabel.translatesAutoresizingMaskIntoConstraints = NO;
  98. pageLabel.backgroundColor = [UIColor clearColor];
  99. pageLabel.textColor = [UIColor whiteColor];
  100. [self.view addSubview:pageLabel];
  101. self.pageLabel = pageLabel;
  102. NSString *widthVfl = @"H:|-0-[pageLabel]-0-|";
  103. NSString *heightVfl = @"V:[pageLabel(ZLPickerPageCtrlH)]-20-|";
  104. NSDictionary *views = NSDictionaryOfVariableBindings(pageLabel);
  105. NSDictionary *metrics = @{@"ZLPickerPageCtrlH":@(ZLPickerPageCtrlH)};
  106. [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:widthVfl options:0 metrics:metrics views:views]];
  107. [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:heightVfl options:0 metrics:metrics views:views]];
  108. }
  109. return _pageLabel;
  110. }
  111. #pragma mark - Life cycle
  112. - (void)viewDidAppear:(BOOL)animated{
  113. [super viewDidAppear:animated];
  114. NSAssert(self.dataSource, @"你没成为数据源代理");
  115. [self collectionView];
  116. // 初始化动画
  117. [self startLogddingAnimation];
  118. }
  119. - (void)dealloc{
  120. [[NSNotificationCenter defaultCenter] removeObserver:self];
  121. }
  122. - (void)viewDidLoad {
  123. [super viewDidLoad];
  124. self.view.backgroundColor = [UIColor blackColor];
  125. }
  126. #pragma mark - Get
  127. #pragma mark getPhotos
  128. - (NSArray *) getPhotos{
  129. NSMutableArray *photos = [NSMutableArray array];
  130. NSInteger section = self.currentIndexPath.section;
  131. NSInteger rows = [self.dataSource photoBrowser:self numberOfItemsInSection:section];
  132. for (NSInteger i = 0; i < rows; i++) {
  133. [photos addObject:[self.dataSource photoBrowser:self photoAtIndexPath:[NSIndexPath indexPathForItem:i inSection:section]]];
  134. }
  135. return photos;
  136. }
  137. #pragma mark get Controller.view
  138. - (UIView *)getParsentView:(UIView *)view{
  139. if ([[view nextResponder] isKindOfClass:[UIViewController class]] || view == nil) {
  140. return view;
  141. }
  142. return [self getParsentView:view.superview];
  143. }
  144. - (id)getParsentViewController:(UIView *)view{
  145. if ([[view nextResponder] isKindOfClass:[UIViewController class]] || view == nil) {
  146. return [view nextResponder];
  147. }
  148. return [self getParsentViewController:view.superview];
  149. }
  150. #pragma makr - init Animation
  151. - (void)startLogddingAnimation{
  152. if (!(self.toView) ) {
  153. [self reloadData];
  154. return;
  155. }
  156. // 判断是否是控制器
  157. UIView *fromView = object_getIvar(self.dataSource, class_getInstanceVariable([self.dataSource class],"_view"));
  158. // 如果是自定义View
  159. if (fromView == nil) {
  160. fromView = [self getParsentView:self.toView];
  161. }
  162. if (!self.currentIndexPath) {
  163. self.currentIndexPath = [NSIndexPath indexPathForItem:self.currentPage inSection:0];
  164. }else{
  165. self.currentPage = self.currentIndexPath.row;
  166. }
  167. NSDictionary *options = @{
  168. UIViewAnimationInView:self.view,
  169. UIViewAnimationFromView:fromView,
  170. UIViewAnimationAnimationStatusType:@(self.status),
  171. UIViewAnimationNavigationHeight : @(self.navigationHeight),
  172. UIViewAnimationToView:self.toView,
  173. UIViewAnimationFromView:self.dataSource,
  174. UIViewAnimationImages:self.photos,
  175. UIViewAnimationTypeViewWithIndexPath:self.currentIndexPath
  176. };
  177. __weak typeof(self) weakSelf = self;
  178. [DKAnimationScrollView animationViewWithOptions:options animations:nil completion:^(DKAnimationBaseView *baseView) {
  179. // disMiss后调用
  180. weakSelf.disMissBlock = ^(NSInteger page){
  181. if (self.currentIndexPath) {
  182. [DKAnimationScrollView setCurrentIndexPath:[NSIndexPath indexPathForItem:page inSection:self.currentIndexPath.section]];
  183. }else{
  184. [DKAnimationScrollView setCurrentIndexPath:[NSIndexPath indexPathForItem:page inSection:0]];
  185. }
  186. [weakSelf dismissViewControllerAnimated:NO completion:nil];
  187. [DKAnimationScrollView restoreAnimation:nil];
  188. };
  189. [weakSelf reloadData];
  190. }];
  191. }
  192. #pragma mark - reloadData
  193. - (void) reloadData{
  194. self.collectionView.dataSource = self;
  195. [self.collectionView reloadData];
  196. // 添加自定义View
  197. if ([self.delegate respondsToSelector:@selector(photoBrowserShowToolBarViewWithphotoBrowser:)]) {
  198. UIView *toolBarView = [self.delegate photoBrowserShowToolBarViewWithphotoBrowser:self];
  199. toolBarView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
  200. CGFloat width = self.view.width;
  201. CGFloat x = self.view.x;
  202. if (toolBarView.width) {
  203. width = toolBarView.width;
  204. }
  205. if (toolBarView.x) {
  206. x = toolBarView.x;
  207. }
  208. toolBarView.frame = CGRectMake(x, self.view.height - 44, width, 44);
  209. [self.view addSubview:toolBarView];
  210. }
  211. [self setPageLabelPage:self.currentPage];
  212. if (self.currentPage >= 0) {
  213. CGFloat attachVal = 0;
  214. if (self.currentPage == [self.dataSource photoBrowser:self numberOfItemsInSection:self.currentIndexPath.section] - 1 && self.currentPage > 0) {
  215. attachVal = ZLPickerColletionViewPadding;
  216. }
  217. self.collectionView.x = -attachVal;
  218. self.collectionView.contentOffset = CGPointMake(self.currentPage * self.collectionView.width, 0);
  219. }
  220. }
  221. #pragma mark - <UICollectionViewDataSource>
  222. - (NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  223. return 1;
  224. }
  225. - (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  226. return [self.dataSource photoBrowser:self numberOfItemsInSection:self.currentIndexPath.section];
  227. }
  228. - (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  229. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:_cellIdentifier forIndexPath:indexPath];
  230. if (self.photos.count) {
  231. cell.backgroundColor = [UIColor clearColor];
  232. DKPhotoPickerBrowserPhoto *photo = self.photos[indexPath.item]; //[self.dataSource photoBrowser:self photoAtIndex:indexPath.item];
  233. if([[cell.contentView.subviews lastObject] isKindOfClass:[UIView class]]){
  234. [[cell.contentView.subviews lastObject] removeFromSuperview];
  235. }
  236. UIView *scrollBoxView = [[UIView alloc] init];
  237. scrollBoxView.frame = [UIScreen mainScreen].bounds;
  238. scrollBoxView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
  239. [cell.contentView addSubview:scrollBoxView];
  240. DKPhotoPickerBrowserPhotoScrollView *scrollView = [[DKPhotoPickerBrowserPhotoScrollView alloc] init];
  241. scrollView.sheet = self.sheet;
  242. scrollView.backgroundColor = [UIColor clearColor];
  243. // 为了监听单击photoView事件
  244. scrollView.frame = [UIScreen mainScreen].bounds;
  245. scrollView.photoScrollViewDelegate = self;
  246. scrollView.photo = photo;
  247. __weak typeof(scrollBoxView)weakScrollBoxView = scrollBoxView;
  248. __weak typeof(self)weakSelf = self;
  249. if ([self.delegate respondsToSelector:@selector(photoBrowser:photoDidSelectView:atIndexPath:)]) {
  250. [[scrollBoxView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
  251. scrollView.callback = ^(id obj){
  252. [weakSelf.delegate photoBrowser:weakSelf photoDidSelectView:weakScrollBoxView atIndexPath:indexPath];
  253. };
  254. }
  255. [scrollBoxView addSubview:scrollView];
  256. scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
  257. if (self.currentPage == self.photos.count - 1 && scrollView.x >= 0 && !collectionView.isDragging) {
  258. UICollectionView *collecitonView2 = (UICollectionView *)[self getScrollViewBaseViewWithCell:self.toView] ;
  259. if ([collecitonView2 isMemberOfClass:[UICollectionView class]]) {
  260. UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)collecitonView2.collectionViewLayout;
  261. if (layout.scrollDirection == UICollectionViewScrollDirectionVertical) {
  262. scrollView.x = -ZLPickerColletionViewPadding;
  263. }else{
  264. }
  265. }else{
  266. scrollView.x = 0;
  267. }
  268. }
  269. }
  270. return cell;
  271. }
  272. #pragma mark - 获取CollectionView
  273. - (UIView *) getScrollViewBaseViewWithCell:(UIView *)view{
  274. for (int i = 0; i < view.subviews.count; i++) {
  275. UICollectionViewCell *cell = view.subviews[i];
  276. if ([cell isKindOfClass:[UICollectionView class]] || [cell isKindOfClass:[UITableView class]] || [cell isKindOfClass:[UIScrollView class]] || view == nil) {
  277. return cell;
  278. }
  279. }
  280. return [self getScrollViewBaseViewWithCell:view.superview];
  281. }
  282. #pragma mark - <UIScrollViewDelegate>
  283. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  284. CGRect tempF = self.collectionView.frame;
  285. NSInteger currentPage = (NSInteger)((scrollView.contentOffset.x / scrollView.width) + 0.5);
  286. if (tempF.size.width < [UIScreen mainScreen].bounds.size.width){
  287. tempF.size.width = [UIScreen mainScreen].bounds.size.width;
  288. }
  289. if ((currentPage < [self.dataSource photoBrowser:self numberOfItemsInSection:self.currentIndexPath.section] - 1) || self.photos.count == 1) {
  290. tempF.origin.x = 0;
  291. }else{
  292. tempF.origin.x = -ZLPickerColletionViewPadding;
  293. }
  294. self.collectionView.frame = tempF;
  295. }
  296. -(void)setPageLabelPage:(NSInteger)page{
  297. self.pageLabel.text = [NSString stringWithFormat:@"%ld / %ld",(long)page + 1, (long)self.photos.count];
  298. }
  299. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
  300. NSInteger currentPage = (NSInteger)scrollView.contentOffset.x / (scrollView.width - ZLPickerColletionViewPadding);
  301. if (currentPage == self.photos.count - 1 && currentPage != self.currentPage && [[[UIDevice currentDevice] systemVersion] doubleValue] >= 8.0) {
  302. self.collectionView.contentOffset = CGPointMake(self.collectionView.contentOffset.x + ZLPickerColletionViewPadding, 0);
  303. }
  304. self.currentPage = currentPage;
  305. [self setPageLabelPage:currentPage];
  306. if ([self.delegate respondsToSelector:@selector(photoBrowser:didCurrentPage:)]) {
  307. [self.delegate photoBrowser:self didCurrentPage:self.currentPage];
  308. }
  309. }
  310. #pragma mark - 展示控制器
  311. - (void)show{
  312. // BOOL animation = !self.toView;
  313. // if (animation) {
  314. //
  315. // }else{
  316. // [[self getParsentViewController:self.toView] presentViewController:self animated:animation completion:nil];
  317. // }
  318. [[[[UIApplication sharedApplication].windows firstObject] rootViewController] presentViewController:self animated:YES completion:nil];
  319. }
  320. #pragma mark - 删除照片
  321. - (void) delete{
  322. // 准备删除
  323. if ([self.delegate respondsToSelector:@selector(photoBrowser:willRemovePhotoAtIndexPath:)]) {
  324. if(![self.delegate photoBrowser:self willRemovePhotoAtIndexPath:[NSIndexPath indexPathForItem:self.currentPage inSection:self.currentIndexPath.section]]){
  325. return ;
  326. }
  327. }
  328. // UIAlertView *removeAlert = [[UIAlertView alloc]
  329. // initWithTitle:@"确定要删除此图片?"
  330. // message:nil
  331. // delegate:self
  332. // cancelButtonTitle:@"取消"
  333. // otherButtonTitles:@"确定", nil];
  334. // [removeAlert show];
  335. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"确定要删除此图片?" preferredStyle:UIAlertControllerStyleAlert];
  336. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  337. }];
  338. UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"确定"
  339. style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  340. NSInteger page = self.currentPage;
  341. if ([self.delegate respondsToSelector:@selector(photoBrowser:removePhotoAtIndexPath:)]) {
  342. [self.delegate photoBrowser:self removePhotoAtIndexPath:[NSIndexPath indexPathForItem:page inSection:self.currentIndexPath.section]];
  343. [self dismissViewControllerAnimated:YES completion:nil];
  344. }
  345. [UIApplication sharedApplication].statusBarHidden = NO;
  346. [self.photos removeObjectAtIndex:self.currentPage];
  347. if (self.currentPage >= self.photos.count) {
  348. self.currentPage--;
  349. }
  350. UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:page inSection:self.currentIndexPath.section]];
  351. if (cell) {
  352. if([[[cell.contentView subviews] lastObject] isKindOfClass:[UIView class]]){
  353. [UIView animateWithDuration:.35 animations:^{
  354. [[[cell.contentView subviews] lastObject] setAlpha:0.0];
  355. } completion:^(BOOL finished) {
  356. [self reloadData];
  357. }];
  358. }
  359. }
  360. if (self.photos.count < 1)
  361. {
  362. [[NSNotificationCenter defaultCenter] removeObserver:self];
  363. [self dismissViewControllerAnimated:YES completion:nil];
  364. [UIApplication sharedApplication].statusBarHidden = NO;
  365. }
  366. }];
  367. UIColor *cancelColor=[UIColor blackColor];
  368. UIColor *sureColor=[UIColor redColor];
  369. [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
  370. [otherAction setValue:sureColor forKey:@"titleTextColor"];
  371. [alertController addAction:cancelAction];
  372. [alertController addAction:otherAction];
  373. [self presentViewController:alertController animated:YES completion:nil];
  374. }
  375. #pragma mark - <PickerPhotoScrollViewDelegate>
  376. - (void)pickerPhotoScrollViewDidSingleClick:(DKPhotoPickerBrowserPhotoScrollView *)photoScrollView{
  377. if (self.disMissBlock) {
  378. if (self.photos.count == 1) {
  379. self.currentPage = 0;
  380. }
  381. self.disMissBlock(self.currentPage);
  382. }else{
  383. [self dismissViewControllerAnimated:YES completion:nil];
  384. }
  385. [[NSNotificationCenter defaultCenter] removeObserver:self];
  386. }
  387. #pragma mark - showHeadPortrait 放大缩小一张图片的情况下(查看头像)
  388. - (void)showHeadPortrait:(UIImageView *)toImageView{
  389. [self showHeadPortrait:toImageView originUrl:nil];
  390. }
  391. - (void)showHeadPortrait:(UIImageView *)toImageView originUrl:(NSString *)originUrl{
  392. UIView *mainView = [[UIView alloc] init];
  393. mainView.backgroundColor = [UIColor blackColor];
  394. mainView.frame = [UIScreen mainScreen].bounds;
  395. [[UIApplication sharedApplication].keyWindow addSubview:mainView];
  396. CGRect tempF = [toImageView.superview convertRect:toImageView.frame toView:[self getParsentView:toImageView]];
  397. UIImageView *imageView = [[UIImageView alloc] init];
  398. imageView.userInteractionEnabled = YES;
  399. imageView.frame = tempF;
  400. imageView.image = toImageView.image;
  401. imageView.contentMode = UIViewContentModeScaleAspectFit;
  402. [mainView addSubview:imageView];
  403. mainView.clipsToBounds = YES;
  404. [UIView animateWithDuration:.25 animations:^{
  405. imageView.frame = [UIScreen mainScreen].bounds;
  406. } completion:^(BOOL finished) {
  407. imageView.hidden = YES;
  408. DKPhotoPickerBrowserPhoto *photo = [[DKPhotoPickerBrowserPhoto alloc] init];
  409. photo.photoURL = [NSURL URLWithString:originUrl];
  410. photo.photoImage = toImageView.image;
  411. photo.thumbImage = toImageView.image;
  412. DKPhotoPickerBrowserPhotoScrollView *scrollView = [[DKPhotoPickerBrowserPhotoScrollView alloc] init];
  413. __weak typeof(DKPhotoPickerBrowserPhotoScrollView *)weakScrollView = scrollView;
  414. scrollView.callback = ^(id obj){
  415. [weakScrollView removeFromSuperview];
  416. mainView.backgroundColor = [UIColor clearColor];
  417. imageView.hidden = NO;
  418. [UIView animateWithDuration:.25 animations:^{
  419. imageView.frame = tempF;
  420. } completion:^(BOOL finished) {
  421. [mainView removeFromSuperview];
  422. }];
  423. };
  424. scrollView.frame = [UIScreen mainScreen].bounds;
  425. scrollView.photo = photo;
  426. [mainView addSubview:scrollView];
  427. }];
  428. }
  429. @end