2009-02-10 34 views
7

我有一個基於標籤欄的應用程序。如何將視圖旋轉到標籤欄應用程序中的風景

我在Interface Builder中構建了2個視圖,一個是縱向模式,另一個是橫向模式。

現在,我想要的iPod應用程序。我想將橫向視圖設爲全屏,並隱藏狀態欄的標籤欄&。

我做工作的這個基本的:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
           duration:(NSTimeInterval)duration { 
    if (self.landscape) { 
     if (toInterfaceOrientation == UIInterfaceOrientationPortrait) 
     { 
      self.view = self.portrait; 
      self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(360)); 
     } 
     else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) 
     { 
      self.view = self.landscape; 
      self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); 
     } 
     else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) 
     { 
      self.view = self.landscape; 
      self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); 
     } 
     else 
     { 
      self.view = self.portrait; 
      self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-180)); 
     } 
    } 
} 

但是所有的工作混亂。橫向視圖不能正確填充區域,並且控件位於錯誤的位置,與首先設計的不同。

而且,我還沒有通過調用

setStatusBarHidden:(BOOL) 
上的UIApplication參考

,像這樣找到了一種方法來隱藏一切......

回答

1

您可以隱藏狀態欄。

- (void)applicationDidFinishLaunching:(UIApplication *)application { 

[application setStatusBarHidden:YES]; 

} 

要擺脫的TabBar的你可以在界面生成器插座引用到您的代碼,並呼籲

[myUITabBar removeFromSuperview]; 

可能的工作,雖然我沒有測試它,至於其他問題,我不是100%,沒有解決過的問題。

1

好吧,這是據我把這個工作:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
           duration:(NSTimeInterval)duration { 
    if (self.landscape) { 
     if (toInterfaceOrientation == UIInterfaceOrientationPortrait) 
     { 
      self.view = self.portrait; 
      //self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(360)); 
     } 
     else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) 
     { 
      self.view = self.landscape; 
      //self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); 
     } 
     else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) 
     { 
      self.view = self.landscape; 
      //self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); 
     } 
     else 
     { 
      self.view = self.portrait; 
      //self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-180)); 
     } 
    } 
} 

現在,在AppDelegate中:

- (void) didRotate:(NSNotification *)notification 
{ 
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 
    [UIView beginAnimations:nil context:NULL]; 

    if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) 
    { 
     [tabBarController.view setAlpha:0.0]; 
     [tabBarController.view removeFromSuperview]; 

     [[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO]; 
    } else { 
     [tabBarController.view setAlpha:1.0]; 
     [[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];  
    } 
    [UIView commitAnimations]; 
} 

但隨後如何將當前視圖設置,以及如何恢復的TabBar?

1

當我看着iPod應用程序時,在我看來,TabBarController視圖並未以任何方式被替換或修改。我認爲tabbarcontroller視圖和coverflow視圖之間只是淡入淡出。

如果我是你,我會嘗試(不知道這是否可能工作)與一個覆蓋流控制器,其視圖顯示在tabBarController的視圖頂部。如果會阻止tabBarController自動控制其視圖,但是此時我會淡出其視圖並淡入覆蓋流視圖,該視圖僅爲橫向視圖。

我不知道statusBar是否會有適當的行爲,我讓你理清了很多細節,但無論如何,我認爲有兩個單獨的控制器,一個是好主意,一個在景觀中顯示,其他(tabBar)以縱向顯示。

希望能幫助你。

1

似乎有相當數量的編碼員希望有一個標籤欄項目將他們帶到橫向視圖全屏(無狀態欄,無標籤欄),然後再回來。

我已經發布了一個關於蘋果開發人員論壇上是否確實可行的查詢,但尚未得到答覆。

爲什麼這很難? (對不起,一個新手問題?似乎有些顯而易見的事情不應該很難)我沒有找到網上的人有一個明確的答案。

5

看看Apple的「AlternateViews」示例代碼。

其基本思想是您可以通過通知檢測設備的物理方位,然後以「模態」方式激活一個新的視圖控制器並讓它請求全屏。通過讓shouldAutorotate ...僅在一個方向上返回YES,您可以禁用界面旋轉,因爲您正在使用通知手動執行所有操作。當你改變物理方向時,你的模態視圖控制器可以被呈現或被解除。

+0

謝謝! – mobius 2011-10-30 19:49:22

相關問題