[英]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.