停止旋转模态UIViewController [英] Stop a modal UIViewController from rotating

查看:163
本文介绍了停止旋转模态UIViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

模态 UIViewController 的父级自动旋转,但是当模态VC启动时,我只希望它以纵向显示而不能旋转。我试过简单地从模式VC中的 shouldAutorotate ...返回NO,但没有快乐。支持iOS 5 +。

The modal UIViewController's parent auto-rotates, but when the modal VC is up I only want it to appear in portrait and not be rotatable. I have tried simply returning NO from shouldAutorotate... in the modal VC, but no joy. Supporting iOS 5+.

任何帮助都非常感谢。

推荐答案

基本上,如果您在 任何容器控制器 (即UINavigationController)上呈现模态控制器,则默认情况下它具有自动旋转方法返回 YES 。所以你必须为你的UINavigation Controller和Deprecate Autorotation制作子类。

Basically, if you presenting Modal Controller on Any Container Controllers (i.e. UINavigationController) it have autorotation method return YES by default. So you have to make subclass for your UINavigation Controller and Deprecate Autorotation there.

对于iOS 5使用方法:

For iOS 5 use method:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {

    return (toInterfaceOrientation == UIInterfaceOrientationPortrait) : self.enableRotations;
}

iOS 6的

for iOS 6:

- (NSUInteger)supportedInterfaceOrientations {

    switch ([UIDevice currentDevice].userInterfaceIdiom) {

        case UIUserInterfaceIdiomPad:   return UIInterfaceOrientationMaskAll;
        case UIUserInterfaceIdiomPhone: return UIInterfaceOrientationMaskPortrait;
    }
}

- (BOOL)shouldAutorotate {

    return NO;
}

这篇关于停止旋转模态UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆