ios - iPad 应用支持全方法,想让某个ViewController在某些场景下不能旋转
本文介绍了ios - iPad 应用支持全方法,想让某个ViewController在某些场景下不能旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
如题,分为场景A和场景B,
场景A下,ViewController能旋转;
场景B下,ViewController不能旋转。
解决方案
在 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
这篇关于ios - iPad 应用支持全方法,想让某个ViewController在某些场景下不能旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文