Skip to content

Commit

Permalink
Merge pull request #27 from andreagiavatto/Issue#19
Browse files Browse the repository at this point in the history
fixed orientation issues when device is laying flat on a surface #19, co...
  • Loading branch information
andreagiavatto committed Apr 18, 2014
2 parents 50b9192 + abe2765 commit 5a1b8cd
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 @@ -391,7 +390,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 @@ -403,7 +402,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 @@ -429,7 +427,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 @@ -462,7 +460,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 @@ -477,7 +475,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 5a1b8cd

Please sign in to comment.