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 .

最后編輯于
?著作權(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)容

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

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