Skip to content

Commit

Permalink
Using pop animation when presenting a photo
Browse files Browse the repository at this point in the history
New property to force hide status bar
  • Loading branch information
eduardocallado committed Jul 15, 2014
1 parent a10911d commit f60c99b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 31 deletions.
1 change: 1 addition & 0 deletions Classes/IDMPhotoBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

@property (nonatomic) BOOL arrowButtonsChangePhotosAnimated;

@property (nonatomic) BOOL forceHideStatusBar;
@property (nonatomic) BOOL usePopAnimation;

// defines zooming of the background (default 1.0)
Expand Down
81 changes: 50 additions & 31 deletions Classes/IDMPhotoBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ @interface IDMPhotoBrowser () {
NSInteger _initalPageIndex;

BOOL _isdraggingPhoto;

CGRect _resizableImageViewFrame;
//UIImage *_backgroundScreenshot;

Expand Down Expand Up @@ -132,6 +132,7 @@ @implementation IDMPhotoBrowser
@synthesize leftArrowImage = _leftArrowImage, rightArrowImage = _rightArrowImage, leftArrowSelectedImage = _leftArrowSelectedImage, rightArrowSelectedImage = _rightArrowSelectedImage;
@synthesize displayArrowButton = _displayArrowButton, actionButtonTitles = _actionButtonTitles;
@synthesize arrowButtonsChangePhotosAnimated = _arrowButtonsChangePhotosAnimated;
@synthesize forceHideStatusBar = _forceHideStatusBar;
@synthesize usePopAnimation = _usePopAnimation;
@synthesize actionsSheet = _actionsSheet, activityViewController = _activityViewController;
@synthesize trackTintColor = _trackTintColor, progressTintColor = _progressTintColor;
Expand Down Expand Up @@ -162,6 +163,7 @@ - (id)init {
_displayArrowButton = YES;
_displayCounterLabel = NO;

_forceHideStatusBar = NO;
_usePopAnimation = NO;

_useWhiteBackgroundColor = NO;
Expand All @@ -178,13 +180,13 @@ - (id)init {

if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)])
self.automaticallyAdjustsScrollViewInsets = NO;

_applicationWindow = [[[UIApplication sharedApplication] delegate] window];

_applicationTopViewController = [self topviewController];

_previousModalPresentationStyle = _applicationTopViewController.modalPresentationStyle;

_applicationTopViewController.modalPresentationStyle = UIModalPresentationCurrentContext;

self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
Expand Down Expand Up @@ -225,7 +227,7 @@ - (id)initWithPhotoURLs:(NSArray *)photoURLsArray {
- (id)initWithPhotoURLs:(NSArray *)photoURLsArray animatedFromView:(UIView*)view {
if ((self = [self init])) {
NSArray *photosArray = [IDMPhoto photosWithURLs:photoURLsArray];
_photos = [[NSMutableArray alloc] initWithArray:photosArray];
_photos = [[NSMutableArray alloc] initWithArray:photosArray];
_senderViewForAnimation = view;
}
return self;
Expand Down Expand Up @@ -324,7 +326,7 @@ - (void)panGestureRecognized:(id)sender {

self.view.backgroundColor = [UIColor colorWithWhite:(_useWhiteBackgroundColor ? 1 : 0) alpha:1];

CGFloat velocityY = (.35*[(UIPanGestureRecognizer*)sender velocityInView:self.view].y);
CGFloat velocityY = (.35*[(UIPanGestureRecognizer*)sender velocityInView:self.view].y);

CGFloat finalX = firstX;
CGFloat finalY = viewHalfHeight;
Expand Down Expand Up @@ -383,29 +385,42 @@ - (void)performPresentAnimation {
[_applicationWindow addSubview:resizableImageView];
_senderViewForAnimation.hidden = YES;

[UIView animateWithDuration:_animationDuration animations:^{
/*CGAffineTransform zoom = CGAffineTransformScale(CGAffineTransformIdentity, _backgroundScaleFactor, _backgroundScaleFactor);
[_applicationRootViewController.view setTransform:zoom];*/

fadeView.backgroundColor = self.useWhiteBackgroundColor ? [UIColor whiteColor] : [UIColor blackColor];

float scaleFactor = (imageFromView ? imageFromView.size.width : screenWidth) / screenWidth;

resizableImageView.frame = CGRectMake(0, (screenHeight/2)-((imageFromView.size.height / scaleFactor)/2), screenWidth, imageFromView.size.height / scaleFactor);
} completion:^(BOOL finished) {
void (^completion)() = ^() {
self.view.alpha = 1.0f;
resizableImageView.backgroundColor = [UIColor colorWithWhite:(_useWhiteBackgroundColor) ? 1 : 0 alpha:1];
[fadeView removeFromSuperview];
[resizableImageView removeFromSuperview];
}];
};

[UIView animateWithDuration:_animationDuration animations:^{
fadeView.backgroundColor = self.useWhiteBackgroundColor ? [UIColor whiteColor] : [UIColor blackColor];
} completion:nil];

if(_usePopAnimation)
{
float scaleFactor = (imageFromView ? imageFromView.size.width : screenWidth) / screenWidth;
CGRect frame = CGRectMake(0, (screenHeight/2)-((imageFromView.size.height / scaleFactor)/2), screenWidth, imageFromView.size.height / scaleFactor);

[self animateView:resizableImageView
toFrame:frame
completion:completion];
}
else
{
[UIView animateWithDuration:_animationDuration animations:^{
resizableImageView.layer.frame = _resizableImageViewFrame;
} completion:^(BOOL finished) {
completion();
}];
}
}

- (void)performCloseAnimationWithScrollView:(IDMZoomingScrollView*)scrollView {
float fadeAlpha = 1 - abs(scrollView.frame.origin.y)/scrollView.frame.size.height;

UIImage *imageFromView = [scrollView.photo underlyingImage];
//imageFromView = [self rotateImageToCurrentOrientation:imageFromView];

CGRect screenBound = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenBound.size.width;
CGFloat screenHeight = screenBound.size.height;
Expand Down Expand Up @@ -534,7 +549,7 @@ - (void)viewDidLoad {
[self.view addSubview:_pagingScrollView];

UIInterfaceOrientation currentOrientation = [UIApplication sharedApplication].statusBarOrientation;

// Toolbar
_toolbar = [[UIToolbar alloc] initWithFrame:[self frameForToolbarAtOrientation:currentOrientation]];
_toolbar.backgroundColor = [UIColor clearColor];
Expand Down Expand Up @@ -629,7 +644,7 @@ - (void)viewWillAppear:(BOOL)animated {

// Status Bar
_statusBarOriginallyHidden = [UIApplication sharedApplication].statusBarHidden;

// Update UI
[self hideControlsAfterDelay];
}
Expand Down Expand Up @@ -660,15 +675,19 @@ - (UIStatusBarStyle)preferredStatusBarStyle {
}

- (BOOL)prefersStatusBarHidden {
if(_isdraggingPhoto)
{
if(_statusBarOriginallyHidden)
if(_forceHideStatusBar) {
return YES;
}

if(_isdraggingPhoto) {
if(_statusBarOriginallyHidden) {
return YES;
else
}
else {
return NO;
}
}
else
{
else {
return [self areControlsHidden];
}
}
Expand All @@ -684,13 +703,13 @@ - (void)viewWillLayoutSubviews {
_performingLayout = YES;

UIInterfaceOrientation currentOrientation = [UIApplication sharedApplication].statusBarOrientation;

// Toolbar
_toolbar.frame = [self frameForToolbarAtOrientation:currentOrientation];

// Done button
_doneButton.frame = [self frameForDoneButtonAtOrientation:currentOrientation];


// Remember index
NSUInteger indexPriorToLayout = _currentPageIndex;
Expand Down Expand Up @@ -815,7 +834,7 @@ - (IDMCaptionView *)captionViewForPhotoAtIndex:(NSUInteger)index {
}
}
captionView.alpha = [self areControlsHidden] ? 0 : 1; // Initial alpha

return captionView;
}

Expand Down Expand Up @@ -1104,7 +1123,7 @@ - (void)jumpToPageAtIndex:(NSUInteger)index {
// Change page
if (index < [self numberOfPhotos]) {
CGRect pageFrame = [self frameForPageAtIndex:index];

if(_arrowButtonsChangePhotosAnimated)
{
[_pagingScrollView setContentOffset:CGPointMake(pageFrame.origin.x - PADDING, 0) animated:YES];
Expand Down Expand Up @@ -1144,7 +1163,7 @@ - (void)setControlsHidden:(BOOL)hidden animated:(BOOL)animated permanent:(BOOL)p
[_doneButton setAlpha:alpha];
for (UIView *v in captionViews) v.alpha = alpha;
} completion:^(BOOL finished) {}];

// Control hiding timer
// Will cancel existing timer but only begin hiding if they are visible
if (!permanent) [self hideControlsAfterDelay];
Expand Down

0 comments on commit f60c99b

Please sign in to comment.