IOS 6 Orientation

故事扮演 提交于 2019-12-25 05:25:13

问题


I am working on a project and facing a problem. My problem is that i am making a project for 5.0 and above, My project is all in portrait view but only one view has both view (Landscape and portrait) i am using NavigationController custom class and check Orientations like this in custom navigation class `

    - (NSUInteger)supportedInterfaceOrientations
  {
int interfaceOrientation = 0;

if (self.viewControllers.count > 0)
{
    id viewController;
    for (viewController in self.viewControllers)
    {
       if ([viewController isKindOfClass:([CalenderViewController class])])
        {
            interfaceOrientation = UIInterfaceOrientationMaskAll;
        }
        else
        {
            interfaceOrientation = UIInterfaceOrientationMaskPortrait;
        }
    }
}
return interfaceOrientation;
}` 

CalenderViewController is my view that supported both view this code works fine for popview when i pop a view to CalenderViewController, this works fine but when i push a new view controller on CalenderViewController that has only portrait view then the new viewcontroller remains in landscape, whereas it should be in portrait mode .Looking forward for a solution thanks


回答1:


In cases like this, you shouldn't return NO on shouldAutorotate. If you do that, supported orientations won't even be checked and your controller will be stuck on the last orientation used.

Instead, just return YES on shouldAutorotate and specifiy a single orientation (portrait) in supportedInterfaceOrientations, like you already do.

Returning YES on shouldAutorotate isn't meant only for when you want you controller to freely rotate to other orientations. It should also be used when you might need your controller to rotate back to its only supported orientation after popping or pushing a view that does differently.



来源:https://stackoverflow.com/questions/18328889/ios-6-orientation

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