Set different supportedInterfaceOrientations for different UIViewControllers

≯℡__Kan透↙ 提交于 2019-12-29 08:12:48

问题


So, as by the question, I use the following code to set userinterfaceOrientation for the viewcontroller.

- (BOOL) shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

I tried setting UIInterfaceOrientationMaskAll for another viewController.

Prior, I checked all the items for Supported interface orientations in the info-plist. Both the viewControllers returned true(as set in the info-plist) for all the orientations and didn't obey the above code. IT worked even in the absence of the above code. Is there anyway to restrict certain Supported interface orientations for particular classes? I made it working for the pre - iOS6 versions by following this link.


回答1:


I was able to accomplish this by placing my supported orientation logic in a custom UINavigationController. I then segue to the relevant view controller.

@implementation PortraitNavigationController

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

...




回答2:


I'd say implement your shouldAutorotateToInterfaceOrientation: on every view controller to make it return only YES for those orientations you wish to support.



来源:https://stackoverflow.com/questions/12600867/set-different-supportedinterfaceorientations-for-different-uiviewcontrollers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!