How to temporarily block orientation of iPad / iPhone

At some point in my application, I would like to temporarily disable the rotation function - to effectively "block" the orientation of the code, similar to what the toggle switch on the lock does on the iPad in hardware.

Now I am doing:

[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications] 

and when I finished, I call:

 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications] 

While this all works, the API documentation indicates that there should always be a beginning, followed by an end, and I am doing this essentially in the reverse order. Is there a more appropriate API for handling "lock orientation"?

+6
objective-c iphone cocoa-touch ipad orientation
source share
1 answer

I think it's as simple as not responding to orientation changes from your controller. You can conditionally return true or false depending on the parameters that you passed, you do not always need to return true.

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if (rand()%2 == 0) { // evaluate if I should allow rotate return YES; } else { return NO; } } 
+10
source share

All Articles