iOS不勾選設置,實現某個界面強制橫屏


 1、在不勾選橫屏的前提下,實現某一個界面橫屏顯示,比如播放視頻、圖表顯示等。

 

2、只能Present跳轉,Push會無效。

3、實現代碼

     在需要橫屏的VC里,添加如下代碼     

#pragma mark 強制橫屏(針對present方式)
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return (UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationLandscapeLeft);
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
}

//必須有
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationLandscapeRight;
}

  

4、最終效果

 

5、其他補充描述

- 這樣設置后,當前頁面的坐標原點會變成橫屏下的左上角,所以適配規則要按照這個來做。

- 橫屏下狀態欄是看不到的,這是系統默認實現。

- 這種方式,即使手機本身設置了禁止旋轉,也是可以旋轉的,所以也是強制旋轉。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM