2013-05-27 90 views
1

在美國的快樂的陣亡將士紀念日!UITabBarController和旋轉iOS6

我是iOS和Objective-C編程的新手,幾個星期前,我繼承了一個爲iOS 5設計的iPad應用程序開發。現在除了iOS 6中的旋轉之外,我現在擁有一切工作。我知道iPad應用程序應該旋轉到默認的每個方向(這就是我想),但我的不是。一切都在iOS 5中完美旋轉,並且我可以讓我的啓動畫面在iOS 6中完美旋轉,但僅此而已。我無法獲得活動(一旦你點擊啓動畫面)就可以正常旋轉。

我已經搜索了stackoverflow和其他網站來弄清楚我必須做什麼,所以我知道在任何特定的ViewController中實現-(BOOL)shouldAutorotate-(NSUInteger)supportedInterfaceOrientations來控制該視圖的方向行爲。我已經讀過,在一個VC中具有不同的旋轉行爲會影響整個應用程序。所以我確保每個我能找到的VC現在都會實現這兩種iOS 6方法,分別返回YESUIInterfaceOrientationMaskAll。這沒有用。我閱讀了關於在這些方法中返回self.tabBarController.shouldAutorotateself.tabBarController.supportedInterfaceOrientations以確保標籤欄旋轉行爲一致,但這不起作用。我已閱讀關於實現一個類(UITabBarController + autoRotate.m和.h),實現這兩個方法,並沒有奏效。我讀過關於繼承的tabBarController,我認爲我的代碼做的是:在我的appDelegate,我叫

[myWindow setRootViewController:activityViewController]

其中activityViewController是類BicycleFamilyAcitivityViewController,這是從

@interface BicycleFamilyActivityViewController : UIViewController <UITabBarControllerDelegate>

的實例

當我調查使用iOS 6模擬器成功啓動屏幕旋轉過程中所調用的內容時,我注意到BicycleFamilyAcitivityViewController中的這兩個實現方法正在被調用(實際上每次調用兩次) nd -(void)willAnimateRotationToInterfaceOrientation:duration也是如此。當我在查看活動時嘗試旋轉時(單擊啓動畫面後),這兩種方法僅調用一次,並且不調用-(void)willAnimateRotationToInterfaceOrientation:duration。在這兩種情況下,調用AppDelegate的-(NSUInteger)application:supportedInterfaceOrientationsForWindow方法。

有關如何讓輪換在整個應用程序中工作的任何建議?即使它只是指向我還沒有看到(或完全理解)的StackOverflow的答案,我將非常感激。

非常感謝提前!

伯尼

**在尋找項目的VC類,我確信考慮到實施的iOS 5的旋轉方法的類:-(BOOL)shouldAutorotateToInterfaceOrientation:interfaceOrientation

回答

0

有人在內部找出問題所在。我想我會發布答案,以幫助任何有類似困境的人。

我曾嘗試過(除其他之外)是:將我的appDelegate類中的UIWindow設置爲UIViewController的子類(BicycleFamilyAcitivityViewController)的實例。在我的appDelegate中,我有:

[myWindow setRootViewController:activityViewController]; 

其中activityViewController是UIViewController的子類的一個實例。

但我應該通過委託創建了一個額外的UIWindow,然後當我構建我的TabBarController時,將TabBarController(tbc)指定爲它的根VC。在我的主視圖控制器類中,我有一個buildTabBarController函數。所以這兩條線的功能允許我的輪換工作:

UIWindow *keyWindow = [[[UIApplication sharedApplication] delegate] window]; 
[keyWindow setRootViewController:tbc]; 

希望這有助於!

0

在iOS 6中的定位功能已經改變。您的設置應該像這樣在你的viewControllers:

-(NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskAll; 
} 

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 
    return UIInterfaceOrientationLandscapeRight; 
} 

-(BOOL)shouldAutorotate { 
    return TRUE; 
} 

UIInterfaceOrientationMaskAll是所有取向更多信息here

+0

謝謝約翰, 我已經在viewControllers中實現了這些方法,保存爲 preferredInterfaceOrientationForPresentation。我在每個viewController中添加了這個方法,以防造成差異。但它不是 。 我知道,個別viewControllers沒有 shouldAutorotate&supportedInterfaceOrientations調用。我想如果我能讓系統進行這些調用,一切都應該落實到位(因爲旋轉在iOS 5中完美運行)。 其他建議? – Bernie

+0

我仍然會投票你的答案,因爲它是一個正確的;但我需要15的聲望才能這樣做! – Bernie

+0

我還沒有弄明白。我的rootVC(BicycleFamilyActivityViewController)中的shouldAutoRotate和supportedInterfaceOrientations方法在循環時被調用,它們返回YES和UIInterfaceOrientationMaskAll,但似乎並沒有旋轉tabbar或任何東西。我可以從這些方法寫出調用subViewControllers中相應的方法,但這沒有幫助。 – Bernie

相關問題