iOS - How to restrict some specific to portrait or landscape mode ?

iOS - How to restrict some specific to portrait or landscape mode ?

Sometimes, you need to disable some specific view controllers to portrait or landscape mode. This is simple . All you need to to is to implement

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

method in Appdelegate.m.

Let's say in my app , there is only StockViewController can be showed as landscape mode.

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    //only stockviewcontroller can be showed in landscape view
    UITabBarController *rootVC = (UITabBarController *)window.rootViewController;
    UINavigationController *rootNavi = (UINavigationController *)rootVC.selectedViewController;
    UIViewController *presentedVC = rootNavi.viewControllers[rootNavi.viewControllers.count - 1];
    if ([presentedVC isKindOfClass:[StockViewController class]]) {
        return UIInterfaceOrientationMaskAll;
    } else {
        return UIInterfaceOrientationMaskPortrait;
    }
}

As you can see , all you need to do is to find out the view controller that is presented by the window's root.rootViewController, and return the orientation you want .

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,941評論 0 23
  • Correctness AdapterViewChildren Summary: AdapterViews can...
    MarcusMa閱讀 8,926評論 0 6
  • 01 女人要有單身的能力 閨蜜優優最近和老公的感情出現了問題,正在鬧離婚。 她問我:“你和老公周末才見面,你就不怕...
    吉馬媽媽Anna閱讀 975評論 0 0
  • 老爸老媽28周年的結婚紀念日,一時興起想為他們寫點東西。我一直覺得我是個極其幸運的人,因為我有最好的爸媽,我所深愛...
    林慕閱讀 407評論 0 0
  • 是夜,夜已深沉 昏暗的房間里女人安然沉睡在床上,突然她感到身體被人緊緊抱住,她知道是她最愛的男人,因為平時睡覺他也...
    莫藝非凡閱讀 145評論 0 0