您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 程式開發 >> iOS 程式設計技術

iOS 橫屏顯示與不同頁面方向控制

編輯:iOS 程式設計技術

在 iOS 中,若要讓 App 整體支援多方向,但一般頁面維持豎屏,可以透過工程設定、AppDelegate 與視圖控制器的 supportedInterfaceOrientations 一起控制。

基本設定

可在 AppDelegate 實作 application:supportedInterfaceOrientationsForWindow:,讓系統知道整個 App 支援哪些方向。

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return UIInterfaceOrientationMaskAll;
}

一般頁面維持豎屏

若使用 UINavigationController 或自訂 BaseViewController,可讓 shouldAutorotate 回傳 YES,但 supportedInterfaceOrientations 只回傳 Portrait。這樣一般頁面會保持豎屏,需要橫屏的頁面再以 present 顯示。

- (BOOL)shouldAutorotate {
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

播放器頁面

播放器若需要支援橫屏,可在該控制器回傳 Landscape 或 All。若同時支援橫豎屏,則回傳 UIInterfaceOrientationMaskAll。

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

此外,若需要控制狀態列顯示或隱藏,可實作 prefersStatusBarHidden,並呼叫 setNeedsStatusBarAppearanceUpdate 更新外觀。

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