我正在处理 appdelegate.m
文件中的所有方向。 supportedInterfaceOrientationsForWindow
为我的一些 View Controller 返回 UIInterfaceOrientationMaskLandscape
,为一个 View Controller 返回 UIInterfaceOrientationMaskPortrait
。
当我从横向 View Controller 移动到纵向 View Controller 时,我想 supportedInterfaceOrientationsForWindow
返回 UIInterfaceOrientationMaskPortrait
但我的 View Controller 显示为横向。
请帮助我,我被困了很长时间。在 iPhone 6、iOS 9 上测试。
最佳答案
假设 View A
是您应用的横向 View 之一,而 B
是预期的纵向 View 。现在,当设备最初在 A 上保持纵向,然后访问 B 时, View 不会将方向更改为纵向(因为设备已经处于纵向)。
我建议“告诉”系统 B 在准备转场时最初是横向的,然后在 B 的 View Controller 的 viewDidLoad
中,将方向更改为纵向。
这样,无论前一个 View 的方向如何,B 在加载时都将始终以纵向打开。
使用以下代码更改方向。如果您使用 segue,请在
中使用此代码- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
这里的方向应该与下一个 View Controller 中所需的方向相反。
关于ios - supportedInterfaceOrientationsForWindow 返回 UIInterfaceOrientationMaskPortrait 但我的 View Controller 显示为横向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35057745/