簡體   English   中英

支持所有方向而無需在iPhone中自動旋轉

[英]Support all orientations without autorotate in iPhone

要求在啟動屏幕之后立即以設備的方向顯示視圖,但是一旦顯示,就不應自動旋轉到其他方向。 我使用此代碼:

- (BOOL)shouldAutorotate {

    [super shouldAutorotate];

    return YES;
}

-(UIInterfaceOrientationMask) supportedInterfaceOrientations {

    [super supportedInterfaceOrientations];

    return UIInterfaceOrientationMaskAll;
}

這在iPad上效果很好,但在iPhone中,僅應在Portrait中將shouldAutorotate結果設置為NO。 這是正常行為嗎? 如果是這樣,如何僅在特定的視圖控制器中在iPhone中支持所有方向而無需自動旋轉?

您需要在啟動時檢測設備所處的方向:

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

將其轉換為界面方向:

switch (orientation) {
    case UIDeviceOrientationLandscapeRight:
        return UIInterfaceOrientationLandscapeLeft;
    default:
        return UIInterfaceOrientationLandscapeRight;
}

現在將其存儲在全局訪問位置,並返回:

- (UIInterfaceOrientationMask) supportedInterfaceOrientations {
    return globalOrientation;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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