ios - supportedInterfaceOrientationsForWindow 返回 UIInterfaceOrientationMaskPortrait 但我的 View Controller 显示为横向

标签 ios objective-c ios9 uiinterfaceorientation

我正在处理 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/

相关文章:

ios - 未调用 Google 登录代理

css - 视网膜手持显示器 : Can a 1px border be achieved via CSS?

ios - 无法传递 UIVewController 的实例 - iOS

objective-c - 无法将属性设置为 NSManagedObject

uitextfield - Xcode UI测试-使用typeText()方法和自动更正键入文本

ios - 在 Objective C 项目中调试 swift 类问题的技术?

ios - 访问 Assets.xcassets 中的所有图像 ?? [ swift 3 ]

ios - 无法实现 UIView 子类

ios - Swift 2 - Xcode 7.0 无法使用不受信任的 SSL 证书访问 HTTPS 站点

ios - PKAddPassButton 不适用于 iOS 9