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

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

    You can use nativeBounds (orientation-independent)

    nativeBounds

    The bounding rectangle of the physical screen, measured in pixels. (read-only)

    Declaration SWIFT

      var nativeBounds: CGRect { get }
    

    This rectangle is based on the device in a portrait-up orientation. This value does not change as the device rotates.

    Detecting the device's height:

    if UIScreen.mainScreen().nativeBounds.height == 960.0 {
    
    }
    

    Detecting the device's width:

    if UIScreen.mainScreen().nativeBounds.width == 640.0 {
    
    }
    

提交回复
热议问题