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