Reputation: 1248
In my app I want some slides of it only to allow orientationPortrait. The problem is I can't disable landscape-mode at all in Xcode. Ive tried the following below and also set Portrait in the storyboard at the slides. What I have understood is, if your classes are connected to tab bars and navigationcontrollers it may not listen to the "standard commands"? What can I do in order to disable all orientations except Portrait in this case ?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Upvotes: 1
Views: 97
Reputation: 689
If you want to restrict the ability to rotate a given viewcontroller you are on the right track with shouldAutoroateToInterfaceOrientation. I personally prefer the cleaner UIInterfaceOrientationIsPortrait() method over a direct comparison though I don't intrinsically see anything wrong with what you did.
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
The things to keep in mind, and what I think may be the problem is that you need to have this method in every viewcontroller you want to restrict rotating in. I would make a main viewcontroller class that contains the above code and subclass it throughout the program to resolve that.
However, this does not stop the program from starting up in landscape mode. To do that you need to go into you Info.plist file and change the "Initial interface orientation" value to portrait. Let me know if that solves your issues, or if it is something else that seems to be causing the problem.
Upvotes: 1