簡體   English   中英

iOS 11設備方向自動旋轉

[英]iOS 11 Device Orientation Autorotation

對於iOS 10及更低版本,以下代碼控制了任何相應UIViewController的方向。 我在部署信息中選擇了PortraitLandscape LeftLandscape 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允許正確的方向...

Objc

- (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版本一樣的旋轉。

Swift 3.2+

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM