簡體   English   中英

選擇新標簽后,iOS UITabBarController不會自動旋轉

[英]iOS UITabBarController does not AutoRotate when a new tab is selected

我有一個帶有5個選項卡的基於UITabBar的iOS應用程序,其中一些選項卡是UINavigationController 我的某些標簽視圖支持橫向,而另一些則不。

我已經為視圖本身做好了所有自動旋轉的工作,但是我在測試應用程序時發現了一些奇特的事情-每當選擇一個新選項卡時,任何UIViewController都不會調用shouldAutoRotateToInterfaceOrientation方法。 有什么方法可以在選擇新標簽時強制進行方向檢查嗎?

創建一個方法並在viewWillAppear調用它以檢查方向,然后根據需要強制執行該方法。

通常,當我看到此消息時,是因為選項卡中的一個shouldAutoRotateToInterfaceOrientation沒有正確設置shouldAutoRotateToInterfaceOrientation 添加到選項卡的所有類都需要設置相同的值,否則它將觸發旋轉。

NOT supported in iOS 6方法shouldAutorotateToInterfaceOrientation:方法。 不推薦使用。 萬一您是一個剛開始從事可可工作的新手,並想知道為什么視圖控制器在iOS 6中混亂而在iOS 5中完美,以防萬一,您應該知道不再支持shouldAutorotateToInterfaceOrientation:。 即使它在Xcode 4 to 4.3上都能很好地NOT work on Xcode 4.5.也無法NOT work on Xcode 4.5.

蘋果提供了一種新的方法來以更清潔的方式完成此任務。 您可以改用supportedInterfaceOrientations。 它返回視圖控制器支持的所有界面方向,以及界面方向值的掩碼。

UIInterfaceOrientationMask Enum:

這些常量是用於指定視圖控制器支持的接口方向的掩碼位。

    typedef enum {
     UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait),
     UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft),
     UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight),
     UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown),
     UIInterfaceOrientationMaskLandscape =
     (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
     UIInterfaceOrientationMaskAll =
     (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
     UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown),
     UIInterfaceOrientationMaskAllButUpsideDown =
     (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
     UIInterfaceOrientationMaskLandscapeRight),
 } UIInterfaceOrientationMask;

適用於iOS的Apple UIViewController編程指南指出:

“標簽欄控制器僅在其所有托管視圖控制器都支持新方向時才允許更改方向。”

如果要支持橫向,則需要確保所有選項卡都支持橫向,因為這是全部或全部的情況。

可能是您使用的是ios 6.0或更高版本,因為在ios 6.0或更高版本中,不建議使用AutoAutoRotateToInterfaceOrientation方法,因此不應該調用它,您必須為UINavigationController和UITabbarContrller創建自己的類別,並添加一些設備旋轉時要調用的方法。

暫無
暫無

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

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