Skip to content

Commit

Permalink
fixed orientation issues when device is laying flat on a surface #19,…
Browse files Browse the repository at this point in the history
… code cleanup
  • Loading branch information
andreagiavatto authored and andreagiavatto committed Feb 3, 2014
1 parent 0831a6e commit abe2765
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
18 changes: 9 additions & 9 deletions src/AGPhotoBrowserCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
10 changes: 4 additions & 6 deletions src/AGPhotoBrowserView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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:^(){
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down

0 comments on commit abe2765

Please sign in to comment.