2011-11-20 68 views
1

我有一個使用UISplitViewController的佈局,每個窗格底部都有一些自定義控件。當我將視圖旋轉到肖像模式時,我想在彈出模式下隱藏主視圖控件。這部分工作正常。顯示/隱藏旋轉前的控件

下面的代碼:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { 
     if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) { 
      _refreshButton.hidden = NO; 
      _aboutButton.hidden = NO; 
      _bottomBar.hidden = NO; 
     } 
     if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { 
      _refreshButton.hidden = YES; 
      _aboutButton.hidden = YES; 
      _bottomBar.hidden = YES; 
     } 
    } 
} 

問題是,當我回旋轉爲橫向模式。控件重新出現,但只有在旋轉完成後。它很實用,但很醜。有沒有辦法強制他們在輪換實際發生之前重新繪製?

+0

只是在黑暗中刺,直到你做,但是你有沒有嘗試將該調用移動到隱藏/顯示代碼下方的超級實現? – Till

+0

@Till:好主意,但沒有骰子。 – peteyfrogboy

回答

0

根據我對蘋果內置動畫的體驗,他們會阻止任何正在進行的操作。當你想要顯示一個預加載器,而你在界面上做了一些非常神奇的功能時,就會發生這種情況。去它的方法就是做你自己的GUI管理在不同的線程:

[self performSelectorInBackground:@selector(showHideMenu) withObject:nil]; 

,或者如果可能的deleying動畫任務中,你想要什麼

[self showHideMenu]; 
[self performSelector:@selector(doRotation) withObject:nil afterDelay:1]; 
+0

第一個選項(一旦我計算出如何做到這一點),在旋轉到縱向視圖之前,控件的效果消失,並在旋轉回風景之後重新出現。我真的不想試圖用自己的視角旋轉猴子,所以我給了第二個選項一個通行證。我現在最終做的是修正視圖頂部的控件距離,並使得彈出窗口足夠短,以免它們以縱向視圖顯示。不是非常優雅的代碼明智,但從用戶的角度看起來更好。 – peteyfrogboy