At a certain point in my application, I would like to temporarily disable the rotation feature - effectively "lock" the orientation in code, similar to what the lock toggle switch does on the iPad in hardware.
I'm currently doing:
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]
and when I'm through, I call:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]
While this all appears to work, the API documentation indicates there should always be a begin followed by an end - and I'm doing it essentially in reverse. Is there a more appropriate API for handling the "lock orientation"?
If you prefer to use the side switch as a mute button, you can lock your iPad's screen orientation by holding the iPad in either landscape or portrait orientation, swiping up to open Control Center, and selecting the Orientation Lock icon.
Make sure that Rotation Lock is off: Swipe down from the top-right corner of your screen to open Control Center. Then tap the Rotation Lock button to make sure it's off.
Simply turn your Apple® iPhone® to change the view. Access the Contol Center by swiping downward from the upper-right corner of the Home or Lock screen. For the iPhone with Touch ID, access the Control Center by touching the bottom of any screen then dragging upward. to lock or unlock screen portrait orientation.
I think it's as simple as not responding to the orientation changes from your controller. You can conditionally return true or false depending on the parameters you are passed, you don't always have to return true.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (rand()%2 == 0) { // evaluate if I should allow rotate
return YES;
} else {
return NO;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With