Is [UIScreen mainScreen].bounds.size becoming orientation-dependent in iOS8?

后端 未结 18 994
北恋
北恋 2020-11-22 16:55

I ran the following code in both iOS 7 and iOS 8:

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
BOOL landsca         


        
18条回答
  •  遥遥无期
    2020-11-22 17:25

    My solution is a combination of MaxK's and hfossli. I made this method on a Category of UIScreen and it has no version checks (which is a bad practice):

    //Always return the iOS8 way - i.e. height is the real orientation dependent height
    + (CGRect)screenBoundsOrientationDependent {
        UIScreen *screen = [UIScreen mainScreen];
        CGRect screenRect;
        if (![screen respondsToSelector:@selector(fixedCoordinateSpace)] && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
            screenRect = CGRectMake(screen.bounds.origin.x, screen.bounds.origin.y, screen.bounds.size.height, screen.bounds.size.width);
        } else {
            screenRect = screen.bounds;
        }
    
        return screenRect;
    }
    

提交回复
热议问题