我有一个导航控制器,它包含一个支持所有方向的Parent UIViewController。我希望我的Parent UIViewController呈现其仅支持Portrait方向的Child UIViewController。如何在iOS 8中完成?
我尝试将supportedInterfaceOrientations设置为仅为我的Child UIViewController返回UIInterfaceOrientationMaskPortrait,但它不起作用。
答案 0 :(得分:1)
一种简单的方法是:
在您的子视图控制器中,您可以定义此委托方法:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
在ViewDidLoad方法的开头添加此行:
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
这是在纵向模式下强制方向的简单解决方案。
答案 1 :(得分:0)
根据更新,似乎有一个正确的答案 Support landscape for only one view in UINavigationController