ios - iPad 应用支持全方法,想让某个ViewController在某些场景下不能旋转
伊谢尔伦
伊谢尔伦 2017-04-17 17:33:41
[iOS讨论组]

如题,分为场景A和场景B,
场景A下,ViewController能旋转;
场景B下,ViewController不能旋转。

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(3)
迷茫

在 ViewController 中添加 shouldAutorotate 方法,里面的逻辑大致如下:

@implementation ViewController
- (BOOL)shouldAutorotate {
    int32_t i = 1;
    if (i == 1) {
        return NO;
    }
    return YES;
}
@end

如果你的 ViewController 是管理在 UINavigationController 中,则需要去修改 UINavigationController 对应的行为,比如通过 Category 的方式实现思路大致如下:

#import "UINavigationController.h"
@implementation UINavigationController (Overrides)
- (BOOL)shouldAutorotate {
    id currentViewController = self.topViewController;
    if ([currentViewController isKindOfClass:[<#your-vc#> class]]) {
        int32_t i = 1; 
        if (i == 1) {
            return NO;
        }
        return YES;
    }
    return YES;
}
@end
天蓬老师

使用shouldAutorotate,具体方法见SamirChen
当用户旋转的时候系统会问Info.plist和顶级的ViewController,如果shouldAutorotate返回NO/Info.plist不允许旋转,则不能旋转

PHP中文网

经过多番尝试,发现:想要旋转设备的时候,访问shouldAutorotate该方法,info.plist中不能把支持的方向全勾上。其次旋转的时候,访问的是跟ViewController的shouldAutorotate。
感谢,大家的帮助。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号