iPhone: How to Prevent Views From Rotating to Landscape View?
-
27-09-2019 - |
Question
I need to block rotation to landscape orientation because my app crashes when it attempts to rotate views to landscape.
How do I block rotation to landscape and where can I setup the block such that it applies to all my views?
Thanks
Solution
In your view controllers:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
if (interfaceOrientation==UIInterfaceOrientationPortrait ) {
return YES;
} else {
return NO;
}
}
This will prevent your views from trying to rotate to landscape or upsidedown-portrait. However, this should be default. If you haven't set up code to handle landscape orientation then the views shouldn't be trying to rotate anyway. Your crashing is most likely coming from somewhere else.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow