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

后端 未结 18 893
北恋
北恋 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:33

    Yes, indeed, screen size is now orientation dependent in iOS 8. Sometimes, however, it's desired to get a size fixed to portrait orientation. Here is how I do it.

    + (CGRect)screenBoundsFixedToPortraitOrientation {
        UIScreen *screen = [UIScreen mainScreen];
    
        if ([screen respondsToSelector:@selector(fixedCoordinateSpace)]) {
                        return [screen.coordinateSpace convertRect:screen.bounds toCoordinateSpace:screen.fixedCoordinateSpace];
        } 
        return screen.bounds;
    }
    

提交回复
热议问题