我正在处理appdelegate.m
文件中的所有方向。 supportedInterfaceOrientationsForWindow
为我的一些视图控制器返回UIInterfaceOrientationMaskLandscape
,为一个视图控制器返回UIInterfaceOrientationMaskPortrait
。
当我从横向视图控制器移动到视图控制器时,我想要纵向supportedInterfaceOrientationsForWindow
返回UIInterfaceOrientationMaskPortrait
,但我的视图控制器以横向显示。
请帮助我,我已经被困了很长时间。在iPhone 6,iOS 9上进行测试。
答案 0 :(得分:1)
我们假设视图A
是您应用的横向视图之一,B
是预期的纵向视图。现在,当设备最初在A上保持纵向时,然后访问B,视图不会将方向更改为纵向(因为设备已经处于纵向状态)。
我建议'告诉'在准备segue时B最初处于横向状态的系统,然后在您的viewDidLoad
B视图控制器中,将方向更改为纵向。
这样,无论先前视图的方向如何,B在加载时都将始终以纵向打开。
使用以下代码更改方向。如果您使用segue,请在
中使用此代码- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
此处的方向应与下一个视图控制器中所需的方向相反。