簡體   English   中英

對所有UIViewControllers使用相同的UIInterfaceOrientation

[英]Using the same UIInterfaceOrientation for all UIViewControllers

現在添加到我的故事板的任何新的UIViewController都需要有一個具有以下代碼的類:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

通過復制/粘貼在每個類上維護哪個很好,但這是否真的有必要? 有沒有更快的方法?

您可以使用“支持的界面方向”鍵在info.plist文件中設置整個應用程序支持的界面方向(您也可以在項目摘要面板中以圖形方式設置)。

如果這沒有幫助(它顯然不是你下面的評論)你可以在UIViewController上添加你的代碼作為一個類別,從而使你不必復制並粘貼到每個控制器。

如果這看起來有些激進,你可以創建一個包含該方法的UIViewController子類,並將其用作所有其他控制器的超類(BaseViewController將是一個好名字)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM