2013-03-27 33 views
0

我的應用程序是一個有兩個選項卡的記分員。選項卡一是實際進行記分的地方,選項卡二包含過去的比賽歷史。只有一個標籤支持旋轉,並且在旋轉時隱藏它的導航和標籤欄(沒有足夠的垂直空間)。我不想在歷史記錄選項卡上支持旋轉,因爲tabbar被隱藏在計數器中。切換選項卡然後讓選項卡消失是相當困難的。iOS 5和6只支持一個選項卡旋轉

在第一個標籤欄中可能會顯示幾種類型的遊戲,即「CounterBase」的所有子類。當新遊戲啓動時,tabbar中的第一個視圖控制器被換出。所有循環代碼都在CounterBase中處理,而不是在其子類中處理。

我試過很多東西來支持旋轉,但它們都是片狀的。目前爲止我得到的最好結果是在第一次加載應用程序時讓一切正常工作,但是在第一次啓動新遊戲時交換停止(交換第一個視圖控制器)。

我發現的一件事是在第一個視圖控制器被換出之後,應用程序委託中的supportedInterfaceOrientationsForWindow不再被調用。

處理這個問題的最佳方法是什麼?

更新我忘了我在iPad上使用標籤欄,因爲它總是隱藏。旋轉在那裏工作得很好,所以現在我倍加困惑。但是,歷史選項卡從不顯示,這可能相關也可能不相關。

更新2我也嘗試使用自定義導航控制器並實現shouldAutorotate。仍然沒有工作。

更新3我發現它並沒有替換導致問題的第一個選項卡,而是在帶有presentViewController的導航控制器中呈現模態視圖:animated:completion :.我曾嘗試在呈現的視圖控制器中覆蓋shouldAutorotate,但它什麼也不做。另外,我在下面的UINavigationController中添加了我正在使用的類別。

這是我目前的執行:

標籤欄控制器類

-(BOOL)shouldAutorotate{ 
     if (self.selectedIndex == 0) // First tab is Counter 
      return YES; 
     else 
      return NO; 
    } 

    - (NSUInteger)supportedInterfaceOrientations{ 
     if (self.selectedIndex==0) { 
      return UIInterfaceOrientationMaskAll; 
     } 
     else { 
      return UIInterfaceOrientationMaskAllButUpsideDown; 
     } 
    } 

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
     ALog(@"Tab bar selectedIndex: %d", self.selectedIndex); 
     return self.selectedIndex == 0; 
    } 

CounterBase

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    if (UI_USER_INTERFACE_IDIOM_PAD()){ 
     return YES; 
    } else if (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown){ 
     return YES; 
    } 
    return NO; 
} 

- (NSUInteger)supportedInterfaceOrientations { 
    if (UI_USER_INTERFACE_IDIOM_PHONE()) 
     return UIInterfaceOrientationMaskAllButUpsideDown; 
    else 
     return UIInterfaceOrientationMaskAll; 
} 

- (BOOL) shouldAutorotate { 
    return YES; 
} 

HistoryBase

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ 
    BilliardsBuddyAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; 
    return appDelegate.tabBarController.selectedIndex == 0; 
} 

-(BOOL)shouldAutorotate{ 
    return NO; 
} 

-(NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationPortrait; 
} 

的AppDelegate

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { 
    ALog(@"Tab bar selectedIndex: %d", tabBarController.selectedIndex); 
    if (tabBarController.selectedIndex == 0 || UI_USER_INTERFACE_IDIOM_PAD()){ 
     return UIInterfaceOrientationMaskAll; 
    } else { 
     return UIInterfaceOrientationMaskPortrait; 
    } 
} 


@implementation UINavigationController (autoRotate) 
-(BOOL)shouldAutorotate { 
    return YES; 
} 
- (NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskAll; 
} 
@end 

回答

0

好了,三天後我終於解決了這個。我正在使用Mugunth Kumar偉大的UIKit categories來呈現一個動作表。顯然UIActionSheet不喜歡有一個不是UIViewController的委託集。 (或者甚至可能是最頂層的視圖控制器,我不確定。)切換回標準的UIActionSheet showFromTabBar解決了這個問題。