2010-08-29 23 views
2

我有一個帶有4個視圖的TabBarController應用程序。 我已經把所有的4個viewControllers自動旋轉方法返回的是:旋轉TabBarController的所有視圖

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 
    return YES; 
} 

多虧了這一點,現在,當我旋轉iPhone旋轉的作品,甚至使用TabBar旋轉。

在每一個視圖中,我可以使用下面的代碼來更新當發生旋轉時,以查看:

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    [self adjustViewsForOrientation:toInterfaceOrientation]; 
} 

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation { 
    if (orientation == UIInterfaceOrientationLandscapeLeft || 
     orientation == UIInterfaceOrientationLandscapeRight) { 

//Here i can update the view when it goes to landscape 

    } 
    else if (orientation == UIInterfaceOrientationPortrait || 
      orientation == UIInterfaceOrientationPortraitUpsideDown) { 

//Here i can update the view when it goes to portrait 

    } 

} 

的問題是,當我使旋轉,只在當前顯示的視圖被更新。如果稍後我更改視圖單擊tabBar,我看到視圖未更新爲新的方向。

有沒有辦法讓所有的視圖知道方向改變?

回答

0

好吧,我發現它! = d

訣竅是使用功能:

- (void)viewWillAppear:(BOOL)animated 

只是把它在你的viewControllers,並插入裏面的代碼更新視圖。請享用!

+0

將此標記爲已回答。 – bstahlhood 2010-08-30 02:14:51

+0

我必須等到明天才能做到! – Abramodj 2010-08-30 07:21:36

+0

我懷疑這隻發生在你已經訪問過的視圖上,而不是你第一次訪問過的視圖。 – fogelbaby 2010-10-19 02:26:49