2009-02-14 47 views
4

我有一個與UITabBarController真正的問題。 我追求的結果如下: 1)在縱向模式下,一個簡單的標籤欄應用程序(帶導航條)沒有什麼太花哨。 2)在橫向模式下,我想使用我自己的UIViewController完全忽略UITabBar。UITabBarController和旋轉

(我試過很多變種)我想最後我不明白爲什麼不「工作」的方法如下:

  • 我有一個自定義的UIViewController(調用此AA)即是假設管理「一切」。
  • 該控制器被添加到應用程序啓動窗口中,並在其loadView中創建兩個控制器:UITabBarController(調用此TBC)和UILandscapeController(調用此LSC)。然後我添加tabbarcontroller視圖作爲AA視圖的子視圖。
  • 現在在AA級我重寫didRotate等等或willRotate等等,基本上想,這個我在兩個視圖之間切換是指類似:(僞代碼): 從縱向去到風景:
  •  
    [TBC.view removeFromSuperView]; 
    [AA.view addSubview:LSC.view]; 
    

    並且當回到肖像反向時它。

     
    [LSC.view removeFromSuperView]; 
    [AA.view addSubview:TBC.view]; 
    

    我有問題(當然,它簡單的旋轉錯誤地創建一個真正弄亂接口)的量是一些完全無法解釋。似乎tabbarcontroller視圖根本不「喜歡」在標準視圖中,而是希望直接附加到屏幕上。 我不知道什麼是實現我的目標的最佳方法,以及爲什麼tabbar不喜歡成爲視圖的子視圖,主要讚賞任何提示。

    -t

    +0

    在這裏,我已經發布了我的解決方案/經驗與旋轉標籤欄控制器:http://stackoverflow.com/a/12774037/751641 – wzbozon 2012-10-08 00:44:31

    回答

    2

    在文檔中檢查出UIViewController實例方法rotatingFooterView

    或者,您可以自己管理TabBar,而不是通過UITabBarController

    +1

    感謝您的提示!然而,我不明白爲什麼我建議的方法不起作用。 我確定必須有一種方法來創建一個我尋求的界面,它非常基本。我錯過了一些簡單的東西。我不認爲這個問題需要創建一個完整的TabBar管理器。 還有其他建議嗎? – Tzur 2009-02-14 13:34:27

    1

    你的問題來自我認爲的錯字。將removeFromSuperView更改爲removeFromSuperview。 雖然,它仍然有問題。標籤欄不能正確旋轉。它向上直到消散。

    如何不刪除標籤欄,並使其透明。

    3

    萬一你仍然需要答案,或者別人絆倒在這,我已經做了同樣的事情,並得到它的工作,但有幾個箍你必須跳過。爲了旋轉的UITabBarController認爲,有四件事情你必須做的:

    1. 切換到視圖
    2. 之前取出狀態欄旋轉視圖的新框架
    3. 添加狀態欄後面到視圖
    4. 切換到視圖。

    我有一個RootRotationController,這是否看起來像這樣:

    @implementation RootRotationController 
    
    #define degreesToRadian(x) (M_PI * (x)/180.0) 
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
        if ((UIInterfaceOrientationPortrait == interfaceOrientation) || (UIInterfaceOrientationPortraitUpsideDown == interfaceOrientation)) { 
         [[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO]; 
        } 
        // Return YES for supported orientations 
        return YES; 
    } 
    
    - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { 
        [super willAnimateRotationToInterfaceOrientation:interfaceOrientation duration:duration]; 
        if (UIInterfaceOrientationLandscapeLeft == interfaceOrientation) { 
         self.view = self.landscape.view; 
         self.view.transform = CGAffineTransformIdentity; 
         self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); 
         self.view.bounds = CGRectMake(0, 0, 480, 300); 
        } else if (UIInterfaceOrientationLandscapeRight == interfaceOrientation) { 
         self.view = self.landscape.view; 
         self.view.transform = CGAffineTransformIdentity; 
         self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); 
         self.view.bounds = CGRectMake(0, 0, 480, 300); 
        } else if (UIInterfaceOrientationPortrait == interfaceOrientation) { 
         mainInterface.view.transform = CGAffineTransformIdentity; 
         mainInterface.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0)); 
         mainInterface.view.bounds = CGRectMake(0, 0, 300, 480); 
         [[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO]; 
         self.view = mainInterface.view; 
        } else if (UIInterfaceOrientationPortraitUpsideDown == interfaceOrientation) { 
         mainInterface.view.transform = CGAffineTransformIdentity; 
         mainInterface.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180)); 
         mainInterface.view.bounds = CGRectMake(0, 0, 300,480); 
         [[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO]; 
         self.view = mainInterface.view; 
        } 
    } 
    

    此外,你應該知道,shouldAutorotateToInterfaceOrientation被稱爲只需添加根控制器的視圖到窗口後,讓你必須在應用程序委託完成之後重新啓用狀態欄。

    相關問題