[英]iOS 11 Device Orientation Autorotation
对于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;
}
我已经在实际设备上测试了这个,而且从iOS 11开始它不起作用。
更奇怪的是,从iOS 11开始记录已注册的设备方向告诉我设备是纵向...当控制器以横向模式加载时......
码:
// In viewDidLoad
NSLog(@"orientation: %lu", [[UIDevice currentDevice] orientation]);
控制台输出:
2017-09-22 15:20:26.225196-0400 <APP_NAME>[2669:1628408] orientation: 1
这可能是在构建和运行应用程序之前向左或向右旋转设备。
无论这是否是一个iOS 11的错误,我似乎偶然发现了这个问题的“解决方案”。 无论出于何种原因,对于iOS 11更改- (BOOL)shouldAutorotate
返回YES
允许正确的方向...
- (BOOL)shouldAutorotate {
[super shouldAutorotate];
if (@available(iOS 11, *)) return YES;
return NO;
}
在组合中,我必须手动检查屏幕尺寸,以查看宽度是大于还是小于屏幕的假定高度。
width = self.view.frame.size.width, height = self.view.frame.size.height;
if (height < width) width = height, height = self.view.frame.size.width;
希望其他人找到这个“错误”的真正原因或者 Apple更新他们的捆绑来处理像所有以前的iOS版本一样的旋转。
override var shouldAutorotate: Bool {
if #available(iOS 11.0, *) {
// Anything else iOS 11 specific
return true
}
return false
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.