Deactivate automatic screen rotation temporarily

For our iPad application, I would like to enable automatic screen rotation in landscape mode (not portrait) to support both possible orientations. However, there are parts of our application during which the user needs to shake and move the iPad in directions and orientations that will cause the automatic rotation function, but should not.

Is it possible to disable and reactivate auto-orientation so that the orientation is locked when entering this section of the application and unlocked when exiting?

+4
source share
1 answer

if a particular section means a different view controller, YES possible

just add this line of code to the controller.

// which orientation that this view controller support - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } // prevent rotation - (BOOL)shouldAutorotate { return NO; } // after present this view controller, which orientation do you prefer ? - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait; } 
+1
source

Source: https://habr.com/ru/post/1495280/


All Articles