ios – Modal UINavigationController – 我无法停止旋转

前端之家收集整理的这篇文章主要介绍了ios – Modal UINavigationController – 我无法停止旋转前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用故事板,我在UITabBarController中嵌入了UINavigationController.
我推出一个视图控制器然后从这个视图控制器我提出了一个带UIViewController的MODAL UINavigationController.

问题是,当模态视图之前的所有视图都不能时,模态视图控制器可以旋转.
如何停止Modal导航控制器允许任何旋转?

我试过添加

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

谢谢

解决方法

尝试分类UINavigationController

@implementation UINavigationController (Rotation_IOS6)

-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

猜你在找的Xcode相关文章