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、其他補充描述
- 這樣設置后,當前頁面的坐標原點會變成橫屏下的左上角,所以適配規則要按照這個來做。
- 橫屏下狀態欄是看不到的,這是系統默認實現。
- 這種方式,即使手機本身設置了禁止旋轉,也是可以旋轉的,所以也是強制旋轉。
