您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 程式開發 >> iOS 開發綜合

iOS 實作:讓指定頁面橫屏、其他頁面豎屏

編輯:iOS 開發綜合

以下示範如何讓 App 中個別頁面強制橫屏,其餘頁面保持豎屏。

在 AppDelegate.h 中新增 @property(nonatomic,assign)NSInteger allowRotation;

在 AppDelegate.m 中加入:

 - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { if (_allowRotation == 1) { return UIInterfaceOrientationMaskLandscapeRight; } else { return (UIInterfaceOrientationMaskPortrait); } }

如此一來,預設所有頁面都是豎屏。接著在需要強制橫屏的頁面控制器 UIViewController 中,引入 #import "AppDelegate.h",然後加入:

 - (void)viewDidLoad { [super viewDidLoad]; AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; appDelegate.allowRotation = 1; }

即可讓個別頁面單獨橫屏。在離開該橫屏頁面前,記得還原狀態:

 AppDelegate *delegate = [[UIApplication sharedApplication]delegate]; delegate.allowRotation = 0;

如此便能完整實現頁面的橫屏切換。以上就是 iOS 中讓個別頁面強制橫屏、其他頁面維持豎屏的做法,希望對大家有所幫助。若有任何疑問,歡迎留言。

  1. 上一篇文章:
  2. 下一篇文章:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved