Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 9 supportedInterfaceOrientations not working

I have a UIViewController with the following code:

- (BOOL) shouldAutorotate {
     return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationPortrait;
}

I am not using a UINavigationController. When this UIViewController is being displayed, the device will still rotate to landscape. I am targeting iOS 9, what's the issue here?

like image 264
Bryan Avatar asked Sep 25 '15 12:09

Bryan


2 Answers

So the issue was that I had defined the allowed orientations in info.plist which apparently overrides anything you do anywhere else throughout the project.

To correct the issue I removed the entries from info.plist and defined them in the project settings. Now everything works as expected.

like image 111
Bryan Avatar answered Oct 21 '22 20:10

Bryan


I don't think Bryan's answer works,for changing the orientations in project settings also changes the info.plist as @mrhangz commented.

If the issue is iOS9 only,it is probably due to the new feature of iOS9 in iPad called Split view.The iOS9 enable Split view by default in particular iPad device,see Apple documents here.

enter image description here The split view forced your app to support all orientations in all view once adoptted.So if you set all orientations support in either info.plist or target general setting,and then split view is supported by default,which will ignore the orientation setting though supportedInterfaceOrientations in your viewController and support all orientations.

As the document written,if you checked Requires full screen in your target settings,then your app will not support split view.Now you can control orientations in code again. enter image description here

like image 37
Xingxing Avatar answered Oct 21 '22 19:10

Xingxing