Force device rotation with +attemptRotationToDeviceOrientation failing

后端 未结 2 1821
醉梦人生
醉梦人生 2021-01-02 13:46

According to the UIViewController docs here,

https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Ref

相关标签:
2条回答
  • 2021-01-02 14:10

    You could try to achieve something with: setStatusBarOrientation:animated: https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/instm/UIApplication/setStatusBarOrientation:animated:

    this fixed for me a similar issue.

    0 讨论(0)
  • 2021-01-02 14:19

    A call to attemptRotationToDeviceOrientation only rotates the orientation of the interface, if and only if, the device itself has been rotated.

    If your view controller only supported portrait orientation, for example, and the user rotated the device to landscape orientation, no interface rotation would occur. While the device was in landscape orientation, let's say your code toggles a flag which allows for landscape orientation. What would happen to the interface orientation? Nothing, because device orientation has already occurred. To get the interface orientation to match the device orientation, you would need to call attemptRotationToDeviceOrientation.

    In my own code, I recently created a custom, multi-part view animation that didn't look right if interface rotation occurred in the middle of it. So I turned off interface rotation during the brief animation. If the user rotated the device during the animation, no interface orientation would occur. However, when interface orientation was turned back on, the interface would not rotate to match the device orientation until I called attemptRotationToDeviceOrientation.

    0 讨论(0)
提交回复
热议问题