Wil*_*ich 8 objective-c orientation ios swift ios11
对于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)
这可能是在构建和运行应用程序之前向左或向右旋转设备.
无论这是否是一个iOS 11的错误,我似乎偶然发现了这个问题的"解决方案".无论出于何种原因,对于iOS 11,更改- (BOOL)shouldAutorotate返回以YES允许正确的方向...
- (BOOL)shouldAutorotate {
[super shouldAutorotate];
if (@available(iOS 11, *)) return YES;
return NO;
}
Run Code Online (Sandbox Code Playgroud)
在组合中,我必须手动检查屏幕尺寸,以查看宽度是大于还是小于屏幕的假定高度.
width = self.view.frame.size.width, height = self.view.frame.size.height;
if (height < width) width = height, height = self.view.frame.size.width;
Run Code Online (Sandbox Code Playgroud)
希望其他人找到这个"错误"的真正原因或者 Apple更新他们的捆绑来处理像所有以前的iOS版本一样的旋转.
override var shouldAutorotate: Bool {
if #available(iOS 11.0, *) {
// Anything else iOS 11 specific
return true
}
return false
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4570 次 |
| 最近记录: |