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

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

    Related to this question as it solved my problem, here two defines I use for screen width and height calculations:

    #define SCREEN_WIDTH (IOS_VERSION_LOWER_THAN_8 ? (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) ? [[UIScreen mainScreen] bounds].size.width : [[UIScreen mainScreen] bounds].size.height) : [[UIScreen mainScreen] bounds].size.width)
    
    #define SCREEN_HEIGHT (IOS_VERSION_LOWER_THAN_8 ? (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) ? [[UIScreen mainScreen] bounds].size.height : [[UIScreen mainScreen] bounds].size.width) : [[UIScreen mainScreen] bounds].size.height)
    
    #define IOS_VERSION_LOWER_THAN_8 (NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1)
    

    If you are supporting both iOS 7 and iOS 8, this is the best solution for this problem.

提交回复
热议问题