Status bar is Landscape, but [[UIApplication sharedApplication] statusBarOrientation] returns portrait

前端 未结 5 2203
粉色の甜心
粉色の甜心 2020-12-13 05:19

This problem appears to be intermittent, but I am not sure why exactly. When running my application on the device (iPad), I have some code to load a scroll view with some im

5条回答
  •  无人及你
    2020-12-13 05:48

    If you are having this issue at launch time, you need to use UIDevice to get the device orientation, since statusBarOrientation will always be portrait until after application:didFinishLaunchingWithOptions:. The only caveat is that you need to enable device orientation notifications prior or asking UIDevice for the orientation.

        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
        UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
        [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
    

提交回复
热议问题