From abe2765683c3d22ea2f40c2fc0de1834131d4df5 Mon Sep 17 00:00:00 2001 From: andreagiavatto Date: Mon, 3 Feb 2014 13:00:06 +0000 Subject: [PATCH] fixed orientation issues when device is laying flat on a surface #19, code cleanup --- src/AGPhotoBrowserCell.m | 18 +++++++++--------- src/AGPhotoBrowserView.m | 10 ++++------ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/AGPhotoBrowserCell.m b/src/AGPhotoBrowserCell.m index bb7f804..59f7d65 100644 --- a/src/AGPhotoBrowserCell.m +++ b/src/AGPhotoBrowserCell.m @@ -51,15 +51,15 @@ - (void)setFrame:(CGRect)frame // -- Force the right frame CGRect correctFrame = frame; UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; - if (UIDeviceOrientationIsPortrait(orientation) || UIDeviceOrientationIsLandscape(orientation)) { - if (UIDeviceOrientationIsPortrait(orientation)) { - correctFrame.size.width = CGRectGetHeight([[UIScreen mainScreen] bounds]); - correctFrame.size.height = CGRectGetWidth([[UIScreen mainScreen] bounds]); - } else { - correctFrame.size.width = CGRectGetWidth([[UIScreen mainScreen] bounds]); - correctFrame.size.height = CGRectGetHeight([[UIScreen mainScreen] bounds]); - } - } + if (UIDeviceOrientationIsPortrait(orientation) || UIDeviceOrientationIsLandscape(orientation) || orientation == UIDeviceOrientationFaceUp) { + if (UIDeviceOrientationIsPortrait(orientation) || orientation == UIDeviceOrientationFaceUp) { + correctFrame.size.width = CGRectGetHeight([[UIScreen mainScreen] bounds]); + correctFrame.size.height = CGRectGetWidth([[UIScreen mainScreen] bounds]); + } else { + correctFrame.size.width = CGRectGetWidth([[UIScreen mainScreen] bounds]); + correctFrame.size.height = CGRectGetHeight([[UIScreen mainScreen] bounds]); + } + } [super setFrame:correctFrame]; } diff --git a/src/AGPhotoBrowserView.m b/src/AGPhotoBrowserView.m index 0bf9e1f..1770316 100644 --- a/src/AGPhotoBrowserView.m +++ b/src/AGPhotoBrowserView.m @@ -143,7 +143,6 @@ - (AGPhotoBrowserOverlayView *)overlayView - (CGFloat)cellHeight { - //UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; if (UIDeviceOrientationIsLandscape(orientation)) { return CGRectGetHeight(self.currentWindow.frame); @@ -390,7 +389,7 @@ - (void)p_imageViewPanned:(UIPanGestureRecognizer *)recognizer UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; CGPoint translatedPoint; - if (UIDeviceOrientationIsPortrait(orientation)) { + if (UIDeviceOrientationIsPortrait(orientation) || orientation == UIDeviceOrientationFaceUp) { translatedPoint = CGPointMake(_startingPanPoint.x - endingPanPoint.y, _startingPanPoint.y); } else if (orientation == UIDeviceOrientationLandscapeLeft) { translatedPoint = CGPointMake(_startingPanPoint.x + endingPanPoint.x, _startingPanPoint.y); @@ -402,7 +401,6 @@ - (void)p_imageViewPanned:(UIPanGestureRecognizer *)recognizer int heightDifference = abs(floor(_startingPanPoint.x - translatedPoint.x)); if (heightDifference <= AGPhotoBrowserThresholdToCenter) { - // -- Back to original center [UIView animateWithDuration:AGPhotoBrowserAnimationDuration animations:^(){ @@ -428,7 +426,7 @@ - (void)p_imageViewPanned:(UIPanGestureRecognizer *)recognizer UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; CGPoint translatedPoint; - if (UIDeviceOrientationIsPortrait(orientation)) { + if (UIDeviceOrientationIsPortrait(orientation) || orientation == UIDeviceOrientationFaceUp) { translatedPoint = CGPointMake(_startingPanPoint.x - middlePanPoint.y, _startingPanPoint.y); } else if (orientation == UIDeviceOrientationLandscapeLeft) { translatedPoint = CGPointMake(_startingPanPoint.x + middlePanPoint.x, _startingPanPoint.y); @@ -461,7 +459,7 @@ - (void)statusBarDidChangeFrame:(NSNotification *)notification { // -- Get the device orientation UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; - if (UIDeviceOrientationIsPortrait(orientation) || UIDeviceOrientationIsLandscape(orientation)) { + if (UIDeviceOrientationIsPortrait(orientation) || UIDeviceOrientationIsLandscape(orientation) || orientation == UIDeviceOrientationFaceUp) { _changingOrientation = YES; CGFloat angleTable = UIInterfaceOrientationAngleOfOrientation(orientation); @@ -476,7 +474,7 @@ - (void)statusBarDidChangeFrame:(NSNotification *)notification // -- Update table [self setTransform:tableTransform andFrame:tableFrame forView:self.photoTableView]; - if (UIDeviceOrientationIsPortrait(orientation)) { + if (UIDeviceOrientationIsPortrait(orientation) || orientation == UIDeviceOrientationFaceUp) { overlayFrame = CGRectMake(0, CGRectGetHeight(tableFrame) - AGPhotoBrowserOverlayInitialHeight, CGRectGetWidth(tableFrame), AGPhotoBrowserOverlayInitialHeight); doneFrame = CGRectMake(CGRectGetWidth(tableFrame) - 60 - 10, 15, 60, 32); } else if (orientation == UIDeviceOrientationLandscapeLeft) {