对于iOS 10及更低版本,以下代码控制任何相应的方向UIViewController.我选择了Portrait,Landscape Left和Landscape Right我的部署信息,并在我下面的Info.plist:
对于那些根本不应该旋转的VC,我有以下代码,我说过,它在iOS 11之前工作
- (BOOL)shouldAutorotate {
[super shouldAutorotate];
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
[super supportedInterfaceOrientations];
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
我已经在实际设备上测试了这个,而且从iOS 11开始它不起作用.
更奇怪的是,从iOS 11开始记录已注册的设备方向告诉我设备是纵向...当控制器以横向模式加载时......
码:
// In viewDidLoad
NSLog(@"orientation: %lu", [[UIDevice currentDevice] orientation]);
Run Code Online (Sandbox Code Playgroud)
控制台输出:
2017-09-22 15:20:26.225196-0400 <APP_NAME>[2669:1628408] orientation: 1
Run Code Online (Sandbox Code Playgroud)
这可能是在构建和运行应用程序之前向左或向右旋转设备.
我正在使用 Xcode 8 GM 并且有一个需要针对 iOS 10 更新的旧项目。
我发现我当前使用 Swift 2.2 版构建的应用商店在 iOS 10 上运行时不支持所需的界面定向功能
简单地说,当我覆盖 supportedInterfaceOrientations() 时,它在 iOS 10 上运行时永远不会被调用。
在以前的版本上它工作正常。
我可以看到签名已更改,因此 supportedInterfaceOrientations 现在是 var 而不是方法,但这似乎只适用于 Swift 3 而不适用于 Swift 2.3。当我尝试在 Swift 2.3 中作为 var 覆盖时,它不会编译,如果我使用旧签名,它在 iOS 10 下永远不会被调用
有任何想法吗?