From 60c6599350d5e34b50a56f27fbb838307348266c Mon Sep 17 00:00:00 2001 From: jerry Date: Tue, 22 Mar 2016 13:22:24 +0800 Subject: [PATCH 01/14] The animation image will be hide during IDMPhotoBrowser is launching When launching the IDMPhotoBrowser, the animation process is hide when the IDMPhotoBrowser is launching, which will give user a feel that the image is moving to the target position, then disappear for a while, and finally show the actual image. This fix will make sure the IDMPhotoBrowser is transparent before the animation is down, which makes the animation very smooth. --- Classes/IDMPhotoBrowser.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Classes/IDMPhotoBrowser.m b/Classes/IDMPhotoBrowser.m index e883bd6c..33e32a56 100644 --- a/Classes/IDMPhotoBrowser.m +++ b/Classes/IDMPhotoBrowser.m @@ -358,6 +358,7 @@ - (void)panGestureRecognized:(id)sender { #pragma mark - Animation - (void)performPresentAnimation { + self.view.backgroundColor = [UIColor clearColor]; self.view.alpha = 0.0f; _pagingScrollView.alpha = 0.0f; @@ -378,6 +379,7 @@ - (void)performPresentAnimation { _senderViewForAnimation.hidden = YES; void (^completion)() = ^() { + self.view.backgroundColor = self.useWhiteBackgroundColor ? [UIColor whiteColor] : [UIColor blackColor]; self.view.alpha = 1.0f; _pagingScrollView.alpha = 1.0f; resizableImageView.backgroundColor = [UIColor colorWithWhite:(_useWhiteBackgroundColor) ? 1 : 0 alpha:1]; From 25f8422aaa13bf8488a4dfc75f680eef0ed55b7b Mon Sep 17 00:00:00 2001 From: jerry <16907478@qq.com> Date: Wed, 23 Mar 2016 15:20:24 +0800 Subject: [PATCH 02/14] Fixed the wrong image loading progress --- Classes/IDMPhoto.m | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Classes/IDMPhoto.m b/Classes/IDMPhoto.m index 29481a43..11d9905d 100644 --- a/Classes/IDMPhoto.m +++ b/Classes/IDMPhoto.m @@ -135,11 +135,18 @@ - (void)loadUnderlyingImageAndNotify { // Load async from file [self performSelectorInBackground:@selector(loadImageFromFileAsync) withObject:nil]; } else if (_photoURL) { + __block CGFloat progress = 0; // Load async from web (using SDWebImageManager) SDWebImageManager *manager = [SDWebImageManager sharedManager]; - [manager downloadImageWithURL:_photoURL options:SDWebImageRetryFailed progress:^(NSInteger receivedSize, NSInteger expectedSize) { - CGFloat progress = ((CGFloat)receivedSize)/((CGFloat)expectedSize); + [manager downloadImageWithURL:_photoURL options:SDWebImageRetryFailed | SDWebImageProgressiveDownload progress:^(NSInteger receivedSize, NSInteger expectedSize) { if (self.progressUpdateBlock) { + if (receivedSize > 0 && expectedSize > 0) { + CGFloat newProgress = ((CGFloat)receivedSize)/((CGFloat)expectedSize); + progress = MAX(newProgress, progress); + } + else { + progress = MIN(1, progress + 0.05); + } self.progressUpdateBlock(progress); } } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { From 1c58d68ed2a2af35381fd4e4bb0bba72f1e3d854 Mon Sep 17 00:00:00 2001 From: jerry <16907478@qq.com> Date: Wed, 23 Mar 2016 15:22:48 +0800 Subject: [PATCH 03/14] Makes sure we can change the initialPageIndex and image view, so that we can have the close animation once user has navigated to other image --- Classes/IDMPhotoBrowser.h | 4 ++++ Classes/IDMPhotoBrowser.m | 11 ++--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Classes/IDMPhotoBrowser.h b/Classes/IDMPhotoBrowser.h index 6fea898c..79863f74 100644 --- a/Classes/IDMPhotoBrowser.h +++ b/Classes/IDMPhotoBrowser.h @@ -56,6 +56,10 @@ // defines zooming of the background (default 1.0) @property (nonatomic) float backgroundScaleFactor; +// Present +@property (nonatomic, strong) UIView *senderViewForAnimation; +@property (nonatomic) NSInteger initalPageIndex; + // animation time (default .28) @property (nonatomic) float animationDuration; diff --git a/Classes/IDMPhotoBrowser.m b/Classes/IDMPhotoBrowser.m index 33e32a56..709d9df8 100644 --- a/Classes/IDMPhotoBrowser.m +++ b/Classes/IDMPhotoBrowser.m @@ -53,15 +53,11 @@ @interface IDMPhotoBrowser () { //UIStatusBarStyle _previousStatusBarStyle; BOOL _statusBarOriginallyHidden; - // Present - UIView *_senderViewForAnimation; - // Misc BOOL _performingLayout; BOOL _rotating; BOOL _viewIsActive; // active as in it's in the view heirarchy BOOL _autoHide; - NSInteger _initalPageIndex; BOOL _isdraggingPhoto; @@ -140,6 +136,8 @@ @implementation IDMPhotoBrowser @synthesize actionsSheet = _actionsSheet, activityViewController = _activityViewController; @synthesize trackTintColor = _trackTintColor, progressTintColor = _progressTintColor; @synthesize delegate = _delegate; +@synthesize senderViewForAnimation = _senderViewForAnimation; +@synthesize initalPageIndex = _initalPageIndex; #pragma mark - NSObject @@ -285,8 +283,6 @@ - (void)panGestureRecognized:(id)sender { firstX = [scrollView center].x; firstY = [scrollView center].y; - _senderViewForAnimation.hidden = (_currentPageIndex == _initalPageIndex); - _isdraggingPhoto = YES; [self setNeedsStatusBarAppearanceUpdate]; } @@ -376,7 +372,6 @@ - (void)performPresentAnimation { resizableImageView.contentMode = _senderViewForAnimation ? _senderViewForAnimation.contentMode : UIViewContentModeScaleAspectFill; resizableImageView.backgroundColor = [UIColor clearColor]; [_applicationWindow addSubview:resizableImageView]; - _senderViewForAnimation.hidden = YES; void (^completion)() = ^() { self.view.backgroundColor = self.useWhiteBackgroundColor ? [UIColor whiteColor] : [UIColor blackColor]; @@ -433,7 +428,6 @@ - (void)performCloseAnimationWithScrollView:(IDMZoomingScrollView*)scrollView { self.view.hidden = YES; void (^completion)() = ^() { - _senderViewForAnimation.hidden = NO; _senderViewForAnimation = nil; _scaleImage = nil; @@ -1250,7 +1244,6 @@ - (void)doneButtonPressed:(id)sender { [self performCloseAnimationWithScrollView:scrollView]; } else { - _senderViewForAnimation.hidden = NO; [self prepareForClosePhotoBrowser]; [self dismissPhotoBrowserAnimated:YES]; } From e46ae9eb7f2b7f70a818f0138e352477d234023c Mon Sep 17 00:00:00 2001 From: jerry <16907478@qq.com> Date: Wed, 23 Mar 2016 15:24:07 +0800 Subject: [PATCH 04/14] Added Norwegian translation --- .../nb.lproj/Localizable.strings | Bin 0 -> 2390 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 Classes/IDMPBLocalizations.bundle/nb.lproj/Localizable.strings diff --git a/Classes/IDMPBLocalizations.bundle/nb.lproj/Localizable.strings b/Classes/IDMPBLocalizations.bundle/nb.lproj/Localizable.strings new file mode 100755 index 0000000000000000000000000000000000000000..2cf587df9bedc5908ceb2e04ec8815364bb312ce GIT binary patch literal 2390 zcmcJQ-EP`I5QXPDPvLSCDHlXl?^^YuX^Ir}4+-@FNN@~^1Ci~9^73uJGn?%$PAZ`Y zWMS;t**!C7&W!*3KD84o?3=B)UvaU@AuYVd9a1eu+6Ys+J?KXc zPVCfv?r(EK>;oO0}!}AD#Az$Eq4N3#9POPwXHfMifKdtri z3qP}9z2p6kl{uD{|7+i~;8{Bqp>ntfC!Uq!l6~P`DX!1%Eo<{6vVC$AVtO98>@jjq zlr6E=*xRX+1?Vr6;!W_os`oM<)#=yfb30(L%rTUOMZ>RK8>ePWcZk9B$reB1WvB@5t%X zC{o5F@^5@@YPT|P4#xNd9v(nQ=#xio`h4%I`R(sS)Vsa{>S^_MK$Ko18!?Jm7KgrJ cmGjrv`%5byP!3)5|K}Hw6VqS*Wti&w7sC5~o&W#< literal 0 HcmV?d00001 From d3d5d6777f1c0a520642d0748df8b8879496966a Mon Sep 17 00:00:00 2001 From: jerry Date: Wed, 23 Mar 2016 16:28:22 +0800 Subject: [PATCH 05/14] Always show close animation as we've updated the entrance image dynamic --- Classes/IDMPhotoBrowser.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/IDMPhotoBrowser.m b/Classes/IDMPhotoBrowser.m index 709d9df8..f2c24f37 100644 --- a/Classes/IDMPhotoBrowser.m +++ b/Classes/IDMPhotoBrowser.m @@ -1239,7 +1239,7 @@ - (void)setInitialPageIndex:(NSUInteger)index { #pragma mark - Buttons - (void)doneButtonPressed:(id)sender { - if (_senderViewForAnimation && _currentPageIndex == _initalPageIndex) { + if (_senderViewForAnimation) { IDMZoomingScrollView *scrollView = [self pageDisplayedAtIndex:_currentPageIndex]; [self performCloseAnimationWithScrollView:scrollView]; } From 3be3df640104c3e52867f008bd7483290aa58b2b Mon Sep 17 00:00:00 2001 From: jerry <16907478@qq.com> Date: Wed, 23 Mar 2016 19:15:08 +0800 Subject: [PATCH 06/14] Enable the initial image will not disappear during the full size image is loading --- Classes/IDMPhotoBrowser.m | 45 +++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/Classes/IDMPhotoBrowser.m b/Classes/IDMPhotoBrowser.m index 709d9df8..a87c68e4 100644 --- a/Classes/IDMPhotoBrowser.m +++ b/Classes/IDMPhotoBrowser.m @@ -9,9 +9,12 @@ #import #import "IDMPhotoBrowser.h" #import "IDMZoomingScrollView.h" - #import "pop/POP.h" +enum { + kFadeViewTag = 4001 +}; + #ifndef IDMPhotoBrowserLocalizedStrings #define IDMPhotoBrowserLocalizedStrings(key) \ NSLocalizedStringFromTableInBundle((key), nil, [NSBundle bundleWithPath:[[NSBundle bundleForClass: self.class] pathForResource:@"IDMPBLocalizations" ofType:@"bundle"]], nil) @@ -65,6 +68,8 @@ @interface IDMPhotoBrowser () { //UIImage *_backgroundScreenshot; UIWindow *_applicationWindow; + + UIImageView *_resizableImageView; // iOS 7 UIViewController *_applicationTopViewController; @@ -301,7 +306,8 @@ - (void)panGestureRecognized:(id)sender { if ([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) { if(scrollView.center.y > viewHalfHeight+40 || scrollView.center.y < viewHalfHeight-40) // Automatic Dismiss View { - if (_senderViewForAnimation && _currentPageIndex == _initalPageIndex) { + [_resizableImageView removeFromSuperview]; + if (_senderViewForAnimation) { [self performCloseAnimationWithScrollView:scrollView]; return; } @@ -354,7 +360,6 @@ - (void)panGestureRecognized:(id)sender { #pragma mark - Animation - (void)performPresentAnimation { - self.view.backgroundColor = [UIColor clearColor]; self.view.alpha = 0.0f; _pagingScrollView.alpha = 0.0f; @@ -364,22 +369,28 @@ - (void)performPresentAnimation { UIView *fadeView = [[UIView alloc] initWithFrame:_applicationWindow.bounds]; fadeView.backgroundColor = [UIColor clearColor]; + fadeView.tag = kFadeViewTag; [_applicationWindow addSubview:fadeView]; - UIImageView *resizableImageView = [[UIImageView alloc] initWithImage:imageFromView]; - resizableImageView.frame = _senderViewOriginalFrame; - resizableImageView.clipsToBounds = YES; - resizableImageView.contentMode = _senderViewForAnimation ? _senderViewForAnimation.contentMode : UIViewContentModeScaleAspectFill; - resizableImageView.backgroundColor = [UIColor clearColor]; - [_applicationWindow addSubview:resizableImageView]; + _resizableImageView = [[UIImageView alloc] initWithImage:imageFromView]; + _resizableImageView.frame = _senderViewOriginalFrame; + _resizableImageView.clipsToBounds = YES; + _resizableImageView.contentMode = _senderViewForAnimation ? _senderViewForAnimation.contentMode : UIViewContentModeScaleAspectFill; + _resizableImageView.backgroundColor = [UIColor clearColor]; + [self.view addSubview:_resizableImageView]; + [self.view sendSubviewToBack:_resizableImageView]; void (^completion)() = ^() { self.view.backgroundColor = self.useWhiteBackgroundColor ? [UIColor whiteColor] : [UIColor blackColor]; self.view.alpha = 1.0f; _pagingScrollView.alpha = 1.0f; - resizableImageView.backgroundColor = [UIColor colorWithWhite:(_useWhiteBackgroundColor) ? 1 : 0 alpha:1]; + _resizableImageView.backgroundColor = [UIColor colorWithWhite:(_useWhiteBackgroundColor) ? 1 : 0 alpha:1]; [fadeView removeFromSuperview]; - [resizableImageView removeFromSuperview]; + + if ([[self photoAtIndex:_currentPageIndex] underlyingImage]) { + [_resizableImageView removeFromSuperview]; + } + //Else, wait after image has been downloaded }; [UIView animateWithDuration:_animationDuration animations:^{ @@ -390,14 +401,14 @@ - (void)performPresentAnimation { if(_usePopAnimation) { - [self animateView:resizableImageView + [self animateView:_resizableImageView toFrame:finalImageViewFrame completion:completion]; } else { [UIView animateWithDuration:_animationDuration animations:^{ - resizableImageView.layer.frame = finalImageViewFrame; + _resizableImageView.layer.frame = finalImageViewFrame; } completion:^(BOOL finished) { completion(); }]; @@ -912,6 +923,9 @@ - (void)handleIDMPhotoLoadingDidEndNotification:(NSNotification *)notification { id photo = [notification object]; IDMZoomingScrollView *page = [self pageDisplayingPhoto:photo]; if (page) { + if (![_applicationWindow viewWithTag:kFadeViewTag]) { + [_resizableImageView removeFromSuperview]; + } if ([photo underlyingImage]) { // Successful load [page displayImage]; @@ -1117,6 +1131,8 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView { NSUInteger previousCurrentPage = _currentPageIndex; _currentPageIndex = index; if (_currentPageIndex != previousCurrentPage) { + [_resizableImageView removeFromSuperview]; + [self didStartViewingPageAtIndex:index]; if(_arrowButtonsChangePhotosAnimated) [self updateToolbar]; @@ -1239,7 +1255,8 @@ - (void)setInitialPageIndex:(NSUInteger)index { #pragma mark - Buttons - (void)doneButtonPressed:(id)sender { - if (_senderViewForAnimation && _currentPageIndex == _initalPageIndex) { + [_resizableImageView removeFromSuperview]; + if (_senderViewForAnimation) { IDMZoomingScrollView *scrollView = [self pageDisplayedAtIndex:_currentPageIndex]; [self performCloseAnimationWithScrollView:scrollView]; } From d9e80b05351e88675304437d488b81c33126e61a Mon Sep 17 00:00:00 2001 From: jerry <16907478@qq.com> Date: Wed, 23 Mar 2016 19:18:37 +0800 Subject: [PATCH 07/14] Remove the animation view once done button is clicked --- Classes/IDMPhotoBrowser.m | 1 + 1 file changed, 1 insertion(+) diff --git a/Classes/IDMPhotoBrowser.m b/Classes/IDMPhotoBrowser.m index 9171f11b..a87c68e4 100644 --- a/Classes/IDMPhotoBrowser.m +++ b/Classes/IDMPhotoBrowser.m @@ -1255,6 +1255,7 @@ - (void)setInitialPageIndex:(NSUInteger)index { #pragma mark - Buttons - (void)doneButtonPressed:(id)sender { + [_resizableImageView removeFromSuperview]; if (_senderViewForAnimation) { IDMZoomingScrollView *scrollView = [self pageDisplayedAtIndex:_currentPageIndex]; [self performCloseAnimationWithScrollView:scrollView]; From b14126a56ef11d1f6fc6a44ea7dafc498312aa5b Mon Sep 17 00:00:00 2001 From: jerry <16907478@qq.com> Date: Tue, 29 Mar 2016 11:02:25 +0800 Subject: [PATCH 08/14] Don't show animation if the view index is large than the max count can be shown in a post --- Classes/IDMPhotoBrowser.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/IDMPhotoBrowser.m b/Classes/IDMPhotoBrowser.m index a87c68e4..4dbc047a 100644 --- a/Classes/IDMPhotoBrowser.m +++ b/Classes/IDMPhotoBrowser.m @@ -307,7 +307,7 @@ - (void)panGestureRecognized:(id)sender { if(scrollView.center.y > viewHalfHeight+40 || scrollView.center.y < viewHalfHeight-40) // Automatic Dismiss View { [_resizableImageView removeFromSuperview]; - if (_senderViewForAnimation) { + if (_senderViewForAnimation && (_currentPageIndex == _initalPageIndex)) { [self performCloseAnimationWithScrollView:scrollView]; return; } @@ -1256,7 +1256,7 @@ - (void)setInitialPageIndex:(NSUInteger)index { - (void)doneButtonPressed:(id)sender { [_resizableImageView removeFromSuperview]; - if (_senderViewForAnimation) { + if (_senderViewForAnimation && (_currentPageIndex == _initalPageIndex)) { IDMZoomingScrollView *scrollView = [self pageDisplayedAtIndex:_currentPageIndex]; [self performCloseAnimationWithScrollView:scrollView]; } From 3ed241f4499f35ec54e4a97b96026cfcb76a773b Mon Sep 17 00:00:00 2001 From: jerry <16907478@qq.com> Date: Tue, 29 Mar 2016 16:13:58 +0800 Subject: [PATCH 09/14] Makes the animation more smoothly --- Classes/IDMPhotoBrowser.m | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/Classes/IDMPhotoBrowser.m b/Classes/IDMPhotoBrowser.m index 4dbc047a..396cdb3c 100644 --- a/Classes/IDMPhotoBrowser.m +++ b/Classes/IDMPhotoBrowser.m @@ -53,7 +53,7 @@ @interface IDMPhotoBrowser () { NSTimer *_controlVisibilityTimer; // Appearance - //UIStatusBarStyle _previousStatusBarStyle; + UIStatusBarStyle _previousStatusBarStyle; BOOL _statusBarOriginallyHidden; // Misc @@ -301,6 +301,10 @@ - (void)panGestureRecognized:(id)sender { self.view.opaque = YES; self.view.backgroundColor = [UIColor colorWithWhite:(_useWhiteBackgroundColor ? 1 : 0) alpha:newAlpha]; + + if (_initalPageIndex == _currentPageIndex) { + _senderViewForAnimation.hidden = YES; + } // Gesture Ended if ([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) { @@ -335,6 +339,9 @@ - (void)panGestureRecognized:(id)sender { } else // Continue Showing View { + if (_initalPageIndex == _currentPageIndex) { + _senderViewForAnimation.hidden = YES; + } _isdraggingPhoto = NO; [self setNeedsStatusBarAppearanceUpdate]; @@ -360,9 +367,12 @@ - (void)panGestureRecognized:(id)sender { #pragma mark - Animation - (void)performPresentAnimation { + self.view.backgroundColor = [UIColor clearColor]; self.view.alpha = 0.0f; _pagingScrollView.alpha = 0.0f; + _senderViewForAnimation.hidden = YES; + UIImage *imageFromView = _scaleImage ? _scaleImage : [self getImageFromView:_senderViewForAnimation]; _senderViewOriginalFrame = [_senderViewForAnimation.superview convertRect:_senderViewForAnimation.frame toView:nil]; @@ -377,20 +387,21 @@ - (void)performPresentAnimation { _resizableImageView.clipsToBounds = YES; _resizableImageView.contentMode = _senderViewForAnimation ? _senderViewForAnimation.contentMode : UIViewContentModeScaleAspectFill; _resizableImageView.backgroundColor = [UIColor clearColor]; - [self.view addSubview:_resizableImageView]; - [self.view sendSubviewToBack:_resizableImageView]; + [_applicationWindow addSubview:_resizableImageView]; void (^completion)() = ^() { self.view.backgroundColor = self.useWhiteBackgroundColor ? [UIColor whiteColor] : [UIColor blackColor]; self.view.alpha = 1.0f; + _senderViewForAnimation.hidden = NO; _pagingScrollView.alpha = 1.0f; _resizableImageView.backgroundColor = [UIColor colorWithWhite:(_useWhiteBackgroundColor) ? 1 : 0 alpha:1]; [fadeView removeFromSuperview]; + [_resizableImageView removeFromSuperview]; - if ([[self photoAtIndex:_currentPageIndex] underlyingImage]) { - [_resizableImageView removeFromSuperview]; + if (![[self photoAtIndex:_currentPageIndex] underlyingImage]) { + [self.view addSubview:_resizableImageView]; + [self.view sendSubviewToBack:_resizableImageView]; } - //Else, wait after image has been downloaded }; [UIView animateWithDuration:_animationDuration animations:^{ @@ -437,10 +448,11 @@ - (void)performCloseAnimationWithScrollView:(IDMZoomingScrollView*)scrollView { resizableImageView.clipsToBounds = YES; [_applicationWindow addSubview:resizableImageView]; self.view.hidden = YES; + _senderViewForAnimation.hidden = YES; void (^completion)() = ^() { - _senderViewForAnimation = nil; _scaleImage = nil; + _senderViewForAnimation.hidden = NO; [fadeView removeFromSuperview]; [resizableImageView removeFromSuperview]; @@ -508,9 +520,14 @@ - (CGRect)animationFrameForImage:(UIImage *)image presenting:(BOOL)presenting sc - (void)prepareForClosePhotoBrowser { // Gesture [_applicationWindow removeGestureRecognizer:_panGesture]; + + [_resizableImageView removeFromSuperview]; _autoHide = NO; + [[UIApplication sharedApplication] setStatusBarHidden:_statusBarOriginallyHidden withAnimation:UIStatusBarAnimationFade]; + [[UIApplication sharedApplication] setStatusBarStyle:_previousStatusBarStyle animated:YES]; + // Controls [NSObject cancelPreviousPerformRequestsWithTarget:self]; // Cancel any pending toggles from taps } @@ -680,6 +697,9 @@ - (void)viewWillAppear:(BOOL)animated { // Status Bar _statusBarOriginallyHidden = [UIApplication sharedApplication].statusBarHidden; + _previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle; + + [[UIApplication sharedApplication] setStatusBarStyle:[self preferredStatusBarStyle] animated:YES]; // Update UI [self hideControlsAfterDelay]; @@ -1212,6 +1232,8 @@ - (void)setControlsHidden:(BOOL)hidden animated:(BOOL)animated permanent:(BOOL)p // Control hiding timer // Will cancel existing timer but only begin hiding if they are visible if (!permanent) [self hideControlsAfterDelay]; + + [[UIApplication sharedApplication] setStatusBarHidden:hidden withAnimation:UIStatusBarAnimationFade]; [self setNeedsStatusBarAppearanceUpdate]; } @@ -1255,7 +1277,6 @@ - (void)setInitialPageIndex:(NSUInteger)index { #pragma mark - Buttons - (void)doneButtonPressed:(id)sender { - [_resizableImageView removeFromSuperview]; if (_senderViewForAnimation && (_currentPageIndex == _initalPageIndex)) { IDMZoomingScrollView *scrollView = [self pageDisplayedAtIndex:_currentPageIndex]; [self performCloseAnimationWithScrollView:scrollView]; From d3073715f3ec5b56d1dbf386f44fa25e05ee0ca9 Mon Sep 17 00:00:00 2001 From: jerry <16907478@qq.com> Date: Wed, 30 Mar 2016 14:52:39 +0800 Subject: [PATCH 10/14] Use white color for the action bar share button --- .../icon_post_slideshow_photo_action@1x.png | Bin 0 -> 388 bytes .../icon_post_slideshow_photo_action@2x.png | Bin 0 -> 635 bytes .../icon_post_slideshow_photo_action@3x.png | Bin 0 -> 1126 bytes Classes/IDMPhotoBrowser.m | 12 ++++++++---- 4 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 Classes/IDMPhotoBrowser.bundle/images/icon_post_slideshow_photo_action@1x.png create mode 100644 Classes/IDMPhotoBrowser.bundle/images/icon_post_slideshow_photo_action@2x.png create mode 100644 Classes/IDMPhotoBrowser.bundle/images/icon_post_slideshow_photo_action@3x.png diff --git a/Classes/IDMPhotoBrowser.bundle/images/icon_post_slideshow_photo_action@1x.png b/Classes/IDMPhotoBrowser.bundle/images/icon_post_slideshow_photo_action@1x.png new file mode 100644 index 0000000000000000000000000000000000000000..8d05ef980322d0cb197f73aa2b3f051b844ce38a GIT binary patch literal 388 zcmV-~0ek+5P)Px$K1oDDR9Fe^R!a)PFckE+ai=#BPvQ|gfruy2rGk(fcn9}_NAM2rrMPnG(w)x3 z7E6?}|6<}N_nTQf#K^Twa8`y`6SF@{$V6nv|PM`oslyL!Ce?l5pZQAd9Z5Zz#n z+!AFKqLtIA^9*MR=QgZ5sLQaJrD6GYm~eVVc_h*xq8=ev(E!TB0QC^9oJ`CQM@~Q) z+!ekuUDr!j*_b9k!&)*{JQKD`Qqy6=S~6CA%st%4<_jYOqV-e7`~`GB?NGkhTCaRZ iu3!R8fC(^x=mcJ;Rw0)g^sog00000j literal 0 HcmV?d00001 diff --git a/Classes/IDMPhotoBrowser.bundle/images/icon_post_slideshow_photo_action@2x.png b/Classes/IDMPhotoBrowser.bundle/images/icon_post_slideshow_photo_action@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..6cf1bca2bc53ad1f2a08c9ee1a1e22f0641f0769 GIT binary patch literal 635 zcmeAS@N?(olHy`uVBq!ia0vp^5g^RL1|$oo8khhn#^NA%Cx&(BWL`2bFqwL~IEGX( zzP%mjb;Lm6*vHVCPiFTL4tBf7@16Xn`}`x`JxyJUnqKgj2u&(A%-wh8fqlTFWhYI3 zzm8a4VlK_a#G%l@fQxX5ZcKPsvzUXW>FA$1X8FNVTrAz9g~@Mgr?4>{Omexh=Ueg= zR;Gi`+(PpA`~RLEx&LiY7HgBQM`7*1&AIaTHVEaM?yt6gD$aE9*qg)Eo9fO#ifA(Z z*4ur2<#&#pweQupxLbdlc9!$xkKD4HuXiV34G+*uNRJf{E}!u#!u7|F_oW_XWuCL2 z@iel}{%ng-*_briEFbW-Obubw|nuf$Pr9cNimTy0$%Z zujwjiOni5kVY}}QC8-0fp11iLZdZw2WYF`tRmO1V+U5>3tq%sT-+lf6;L)jbZ!G3N zTblp<4A0f{TNwwg*GAl$n>s^&YnlAce3gcy_ZXOU#01*an;FHpI}T4i$k5GtpZY{63N5X|Ut2vgrzdkG^C}DDaCC9RzbDLEa3^MvIKgvJ- zHYVpN3)|VV;`=q~-`}#++GbXNZh=g+Vxwd6r&hgF)jx|XbL*|QiC#~uZI+1^1PZTo z-JU%0d(r0fPq)55Tk~|!`WO8F#O%<`yrEi|P#{Cv(P0+c^ z=6gVV3sCCbJdKsl_k5D=s;-=Pz0O5Z!h5TA)d!{ZN4M;l?*De9)GJH<<#SJgB#U*n zZ4A#;Up?pQ&n0y)H%y%0msdE^|14MR+2dQ+YTP*S*TU?Z*4t-V>7|A%7Zn&U6MMhu zKj)!!nxA^_teI0A`*QkL?n9@-%C6+i=2$lUtyFr|Kc&x;UF}TyYYmtiw($2gM2{P+2>Tr7RLom0P>~X;E*W26s&t3Rxf4ai3cwX-MkVkjvi+H-!6h2Qrd zI%eC|dUciSHq8)rnaq0UyR%}4Mn~=E*gF**O4E8ol|FgQtQ7oVp~@51u_INXV~T$B z+sSSMw{I?a`BCXZp%g>iq8!P>(;sqzj&Ue)DcSaaVc5d+BlpnpH3FKPE{-a$1%|m{ z9U2^A9o)GBoesamJ*pUl8skN4=6n)uQV?(vuxoM<;7}595MX52cBxT5S>2(~Kc`c? zu|N1yLTg8~Tb0~P#tg|1tDE|R*9qwUzxH(_*C$W&UxxSI+}@aX>s76Q%k|p8!ZU_~ z38x*{8X1~6EIb5Qq&QdvTn;!kDO_++Xi#9{6Jlv(V`5|xESR9cVIshx(9zJ$;<%vE zfx(eQMumfkmjxI{4-^~)G8DiL;cRkXCc&sBPwk)XUi;}zbY^Exo^Mol{o6Zt>Q`A8 zJe{?QG5T2J>b+YYM&B{Ir^~B!o|_t3&p|=p2RrAq-6z)nkU0h{I2b%#{an^LB{Ts5 D?JBg^ literal 0 HcmV?d00001 diff --git a/Classes/IDMPhotoBrowser.m b/Classes/IDMPhotoBrowser.m index 396cdb3c..b643a0bf 100644 --- a/Classes/IDMPhotoBrowser.m +++ b/Classes/IDMPhotoBrowser.m @@ -41,8 +41,9 @@ @interface IDMPhotoBrowser () { // Toolbar UIToolbar *_toolbar; - UIBarButtonItem *_previousButton, *_nextButton, *_actionButton; + UIBarButtonItem *_previousButton, *_nextButton, *_actionButton;; UIBarButtonItem *_counterButton; + UILabel *_counterLabel; // Actions @@ -672,9 +673,12 @@ - (void)viewDidLoad { _counterButton = [[UIBarButtonItem alloc] initWithCustomView:_counterLabel]; // Action Button - _actionButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction - target:self - action:@selector(actionButtonPressed:)]; + UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)]; + [button setImage:[[UIImage imageNamed:@"IDMPhotoBrowser.bundle/images/icon_post_slideshow_photo_action"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal]; + button.tintColor = [UIColor whiteColor]; + [button addTarget:self action:@selector(actionButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; + + _actionButton = [[UIBarButtonItem alloc] initWithCustomView:button]; // Gesture _panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureRecognized:)]; From b226bdf041b6b273cbcef3b0fe6a3e4d80793497 Mon Sep 17 00:00:00 2001 From: jerry <16907478@qq.com> Date: Fri, 1 Apr 2016 10:56:49 +0800 Subject: [PATCH 11/14] Prevent the tapping is disabled for some seconds after the image slide view as already been dismissed --- Classes/IDMPhotoBrowser.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/IDMPhotoBrowser.m b/Classes/IDMPhotoBrowser.m index b643a0bf..a84553d8 100644 --- a/Classes/IDMPhotoBrowser.m +++ b/Classes/IDMPhotoBrowser.m @@ -1287,7 +1287,7 @@ - (void)doneButtonPressed:(id)sender { } else { [self prepareForClosePhotoBrowser]; - [self dismissPhotoBrowserAnimated:YES]; + [self dismissPhotoBrowserAnimated:NO]; } } From 782140b04babbdbd53d465baf17169e202d63bc7 Mon Sep 17 00:00:00 2001 From: jerry <16907478@qq.com> Date: Fri, 1 Apr 2016 11:29:57 +0800 Subject: [PATCH 12/14] Don't show present animation if the initial view isn't set --- Classes/IDMPhotoBrowser.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Classes/IDMPhotoBrowser.m b/Classes/IDMPhotoBrowser.m index a84553d8..098c46cc 100644 --- a/Classes/IDMPhotoBrowser.m +++ b/Classes/IDMPhotoBrowser.m @@ -600,7 +600,9 @@ - (void)viewDidLoad { [self.view addSubview:_pagingScrollView]; // Transition animation - [self performPresentAnimation]; + if (_senderViewForAnimation) { + [self performPresentAnimation]; + } UIInterfaceOrientation currentOrientation = [UIApplication sharedApplication].statusBarOrientation; From e466c32ee297fc0ac0dbf6ab4d022efee8333d04 Mon Sep 17 00:00:00 2001 From: jerry <16907478@qq.com> Date: Thu, 7 Apr 2016 17:46:35 +0800 Subject: [PATCH 13/14] Added support for animated from a smart cropping image --- Classes/IDMPhotoBrowser.h | 5 ++++- Classes/IDMPhotoBrowser.m | 44 +++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/Classes/IDMPhotoBrowser.h b/Classes/IDMPhotoBrowser.h index 79863f74..321f4f74 100644 --- a/Classes/IDMPhotoBrowser.h +++ b/Classes/IDMPhotoBrowser.h @@ -58,7 +58,10 @@ // Present @property (nonatomic, strong) UIView *senderViewForAnimation; -@property (nonatomic) NSInteger initalPageIndex; + +@property (nonatomic) CGFloat senderViewImageXOffset; +@property (nonatomic) CGFloat senderViewImageYOffset; +@property (nonatomic) CGSize senderViewOriginalSize; // animation time (default .28) @property (nonatomic) float animationDuration; diff --git a/Classes/IDMPhotoBrowser.m b/Classes/IDMPhotoBrowser.m index 098c46cc..acc43120 100644 --- a/Classes/IDMPhotoBrowser.m +++ b/Classes/IDMPhotoBrowser.m @@ -81,6 +81,8 @@ @interface IDMPhotoBrowser () { @property (nonatomic, strong) UIActionSheet *actionsSheet; @property (nonatomic, strong) UIActivityViewController *activityViewController; +@property (nonatomic) NSInteger initialPageIndex; + // Private Methods // Layout @@ -143,7 +145,6 @@ @implementation IDMPhotoBrowser @synthesize trackTintColor = _trackTintColor, progressTintColor = _progressTintColor; @synthesize delegate = _delegate; @synthesize senderViewForAnimation = _senderViewForAnimation; -@synthesize initalPageIndex = _initalPageIndex; #pragma mark - NSObject @@ -159,7 +160,7 @@ - (id)init { _recycledPages = [NSMutableSet new]; _photos = [NSMutableArray new]; - _initalPageIndex = 0; + _initialPageIndex = 0; _autoHide = YES; _displayDoneButton = YES; @@ -303,7 +304,7 @@ - (void)panGestureRecognized:(id)sender { self.view.backgroundColor = [UIColor colorWithWhite:(_useWhiteBackgroundColor ? 1 : 0) alpha:newAlpha]; - if (_initalPageIndex == _currentPageIndex) { + if (_initialPageIndex == _currentPageIndex) { _senderViewForAnimation.hidden = YES; } @@ -312,7 +313,7 @@ - (void)panGestureRecognized:(id)sender { if(scrollView.center.y > viewHalfHeight+40 || scrollView.center.y < viewHalfHeight-40) // Automatic Dismiss View { [_resizableImageView removeFromSuperview]; - if (_senderViewForAnimation && (_currentPageIndex == _initalPageIndex)) { + if (_senderViewForAnimation && (_currentPageIndex == _initialPageIndex)) { [self performCloseAnimationWithScrollView:scrollView]; return; } @@ -340,7 +341,7 @@ - (void)panGestureRecognized:(id)sender { } else // Continue Showing View { - if (_initalPageIndex == _currentPageIndex) { + if (_initialPageIndex == _currentPageIndex) { _senderViewForAnimation.hidden = YES; } _isdraggingPhoto = NO; @@ -372,9 +373,9 @@ - (void)performPresentAnimation { self.view.alpha = 0.0f; _pagingScrollView.alpha = 0.0f; - _senderViewForAnimation.hidden = YES; - UIImage *imageFromView = _scaleImage ? _scaleImage : [self getImageFromView:_senderViewForAnimation]; + + _senderViewForAnimation.hidden = YES; _senderViewOriginalFrame = [_senderViewForAnimation.superview convertRect:_senderViewForAnimation.frame toView:nil]; @@ -430,7 +431,7 @@ - (void)performPresentAnimation { - (void)performCloseAnimationWithScrollView:(IDMZoomingScrollView*)scrollView { float fadeAlpha = 1 - fabs(scrollView.frame.origin.y)/scrollView.frame.size.height; - UIImage *imageFromView = [scrollView.photo underlyingImage]; + UIImage *imageFromView = _scaleImage ? _scaleImage : [self getImageFromView:_senderViewForAnimation]; if (!imageFromView && [scrollView.photo respondsToSelector:@selector(placeholderImage)]) { imageFromView = [scrollView.photo placeholderImage]; } @@ -447,6 +448,7 @@ - (void)performCloseAnimationWithScrollView:(IDMZoomingScrollView*)scrollView { resizableImageView.contentMode = _senderViewForAnimation ? _senderViewForAnimation.contentMode : UIViewContentModeScaleAspectFill; resizableImageView.backgroundColor = [UIColor clearColor]; resizableImageView.clipsToBounds = YES; + [_applicationWindow addSubview:resizableImageView]; self.view.hidden = YES; _senderViewForAnimation.hidden = YES; @@ -491,7 +493,7 @@ - (CGRect)animationFrameForImage:(UIImage *)image presenting:(BOOL)presenting sc return CGRectZero; } - CGSize imageSize = image.size; + CGSize imageSize = self.senderViewOriginalSize; CGFloat maxWidth = CGRectGetWidth(_applicationWindow.bounds); CGFloat maxHeight = CGRectGetHeight(_applicationWindow.bounds); @@ -499,20 +501,36 @@ - (CGRect)animationFrameForImage:(UIImage *)image presenting:(BOOL)presenting sc CGRect animationFrame = CGRectZero; CGFloat aspect = imageSize.width / imageSize.height; + CGFloat originalImageAspect = image.size.width/image.size.height; + + CGSize targetSize = CGSizeZero; if (maxWidth / aspect <= maxHeight) { animationFrame.size = CGSizeMake(maxWidth, maxWidth / aspect); } else { animationFrame.size = CGSizeMake(maxHeight * aspect, maxHeight); } - + + if (originalImageAspect < animationFrame.size.width/animationFrame.size.height) { + targetSize = CGSizeMake(animationFrame.size.height*originalImageAspect, animationFrame.size.height); + } + else { + targetSize = CGSizeMake(animationFrame.size.width, animationFrame.size.width/originalImageAspect); + } + animationFrame.origin.x = roundf((maxWidth - animationFrame.size.width) / 2.0f); animationFrame.origin.y = roundf((maxHeight - animationFrame.size.height) / 2.0f); + CGFloat scaleRatio = animationFrame.size.height/imageSize.height; + + animationFrame.size = targetSize; if (!presenting) { animationFrame.origin.y += scrollView.frame.origin.y; } + animationFrame = CGRectMake(animationFrame.origin.x + _senderViewImageXOffset * scaleRatio, animationFrame.origin.y + _senderViewImageYOffset * scaleRatio, animationFrame.size.width, animationFrame.size.height); + + return animationFrame; } @@ -1272,7 +1290,7 @@ - (void)toggleControls { [self setControlsHidden:![self areControlsHidden] an - (void)setInitialPageIndex:(NSUInteger)index { // Validate if (index >= [self numberOfPhotos]) index = [self numberOfPhotos]-1; - _initalPageIndex = index; + _initialPageIndex = index; _currentPageIndex = index; if ([self isViewLoaded]) { [self jumpToPageAtIndex:index]; @@ -1283,13 +1301,13 @@ - (void)setInitialPageIndex:(NSUInteger)index { #pragma mark - Buttons - (void)doneButtonPressed:(id)sender { - if (_senderViewForAnimation && (_currentPageIndex == _initalPageIndex)) { + if (_senderViewForAnimation && (_currentPageIndex == _initialPageIndex)) { IDMZoomingScrollView *scrollView = [self pageDisplayedAtIndex:_currentPageIndex]; [self performCloseAnimationWithScrollView:scrollView]; } else { [self prepareForClosePhotoBrowser]; - [self dismissPhotoBrowserAnimated:NO]; + [self dismissPhotoBrowserAnimated:YES]; } } From 8b76483d768882c878381cdbf74bc34c3cc33bc7 Mon Sep 17 00:00:00 2001 From: jerry <16907478@qq.com> Date: Thu, 7 Apr 2016 18:01:00 +0800 Subject: [PATCH 14/14] Fixed a crash issue if we show the animation too early before we get the image's original size --- Classes/IDMPhotoBrowser.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Classes/IDMPhotoBrowser.m b/Classes/IDMPhotoBrowser.m index acc43120..290afb8c 100644 --- a/Classes/IDMPhotoBrowser.m +++ b/Classes/IDMPhotoBrowser.m @@ -618,7 +618,7 @@ - (void)viewDidLoad { [self.view addSubview:_pagingScrollView]; // Transition animation - if (_senderViewForAnimation) { + if ([self shouldShowAnimation]) { [self performPresentAnimation]; } @@ -1300,8 +1300,12 @@ - (void)setInitialPageIndex:(NSUInteger)index { #pragma mark - Buttons +- (BOOL)shouldShowAnimation { + return _senderViewForAnimation && [(UIImageView*)_senderViewForAnimation image] && !CGSizeEqualToSize(self.senderViewOriginalSize, CGSizeZero); +} + - (void)doneButtonPressed:(id)sender { - if (_senderViewForAnimation && (_currentPageIndex == _initialPageIndex)) { + if ([self shouldShowAnimation] && (_currentPageIndex == _initialPageIndex)) { IDMZoomingScrollView *scrollView = [self pageDisplayedAtIndex:_currentPageIndex]; [self performCloseAnimationWithScrollView:scrollView]; }