iOS純代碼實現(xiàn) 強制橫屏

iOS9.0強制橫屏

適用于“當需要在某個豎屏的情況下點擊一個按鈕跳轉(zhuǎn)到另一個橫屏的controller”

  • 首先 :在UINavigationViewController.m中重寫以下三個方法,目的是為了在頁面跳轉(zhuǎn)和返回的時候讓一級二級controller都找到自己支持的橫豎屏模式,否則從橫屏返回的時候會出現(xiàn)崩潰的情況
- (BOOL) shouldAutorotate {    
    return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations { 
    return [self.viewControllers.lastObject supportedInterfaceOrientations];
}
- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
    return [self.viewControllers.lastObject referredInterfaceOrientationForPresentation];
}
  • 其次 :在你需要橫屏的那個第二級controller.m里面重寫三個方法:
- (BOOL)shouldAutorotate {
    return YES;
}
- (UIInterfaceOrientationMask) supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
**//此處填寫你需要讓第二級controller現(xiàn)實的橫屏方向**
    return UIInterfaceOrientationLandscapeLeft;
}
  • 最后:要注意一些細節(jié)點,只能用present不能用push.

要看的更真切的話,用代碼說話.
請轉(zhuǎn)到我的github:https://github.com/FocusLyn/LandscapeLeft

That's all. Thx reading.
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容