[英]iOS 11 Device Orientation Autorotation
For iOS 10 and below, the following code controlled the orientation of the any respective UIViewController
. 对于iOS 10及更低版本,以下代码控制了任何相应
UIViewController
的方向。 I have selected Portrait
, Landscape Left
, and Landscape Right
in my Deployment Info, and have the following in my Info.plist : 我在部署信息中选择了
Portrait
, Landscape Left
和Landscape Right
,并在我的Info.plist中有以下内容:
For my VC's that should not rotate at all I have the following code, which I stated, was working prior iOS 11 对于那些根本不应该旋转的VC,我有以下代码,我说过,它在iOS 11之前工作
- (BOOL)shouldAutorotate {
[super shouldAutorotate];
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
[super supportedInterfaceOrientations];
return UIInterfaceOrientationMaskPortrait;
}
I have tested this on actual devices and as of iOS 11 it does not work. 我已经在实际设备上测试了这个,而且从iOS 11开始它不起作用。
Even more strangely, logging the registered device orientation as of iOS 11 tells my the device IS portrait... when the controller loads in landscape mode... 更奇怪的是,从iOS 11开始记录已注册的设备方向告诉我设备是纵向...当控制器以横向模式加载时......
Code: 码:
// In viewDidLoad
NSLog(@"orientation: %lu", [[UIDevice currentDevice] orientation]);
Console output: 控制台输出:
2017-09-22 15:20:26.225196-0400 <APP_NAME>[2669:1628408] orientation: 1
This occurs either rotating the device left or right before building and running the app. 这可能是在构建和运行应用程序之前向左或向右旋转设备。
Whether this proves to be an iOS 11 bug or not, I seemed to have stumbled upon a "solution" to this issue. 无论这是否是一个iOS 11的错误,我似乎偶然发现了这个问题的“解决方案”。 For whatever reason, for iOS 11 changing the
- (BOOL)shouldAutorotate
return to YES
allows for the correct orientation... 无论出于何种原因,对于iOS 11更改
- (BOOL)shouldAutorotate
返回YES
允许正确的方向...
- (BOOL)shouldAutorotate {
[super shouldAutorotate];
if (@available(iOS 11, *)) return YES;
return NO;
}
In combination I had to do a manual check for the screen dimensions to see if the width was greater or less than the supposed height of the screen. 在组合中,我必须手动检查屏幕尺寸,以查看宽度是大于还是小于屏幕的假定高度。
width = self.view.frame.size.width, height = self.view.frame.size.height;
if (height < width) width = height, height = self.view.frame.size.width;
Hopefully someone else finds the true cause of this "bug" OR Apple updates their bundle to handle rotations like all previous iOS versions.. 希望其他人找到这个“错误”的真正原因或者 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.