2015-01-14 61 views
1

我在iOS 8中有一個自定義UISplitViewController子類。在橫向上,我希望主VC和次VC的默認行爲可見(),但當我旋轉到肖像我想主要的VC顯示在默認彈出窗口(preferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay)。在分割視圖旋轉時手動設置preferredDisplayMode時,主視圖控制器內容會消失

通過在子類上實現-viewWillTransitionToSize:我可以得到這個工作,但旋轉了幾次後,主VC消失並且不會再出現,直到我點擊分割視圖的酒吧按鈕項。

第一對旋轉中的旋轉動畫完成塊中的日誌顯示首選顯示模式與實際顯示模式相同,但在旋轉幾圈之後,實際顯示模式在橫向上被鎖定爲UISplitViewControllerDisplayModePrimaryOverlay,即使在首選的顯示模式是UISplitViewControllerDisplayModeAllVisible

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator { 
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; 

    if (self.traitCollection.userInterfaceIdiom == UIUserInterfaceIdiomPad) { 
     BOOL isPortrait = size.height > size.width; 

     if (isPortrait) { 
      self.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay; 
     } 
     else { 
      self.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible; 
     } 

     [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { 
      self.dividerView.hidden = isPortrait; 
     } completion:^(id<UIViewControllerTransitionCoordinatorContext> context) { 
      NSLog(@"Preferred display mode: %ld | Actual display mode: %ld", self.preferredDisplayMode, self.displayMode); 
     }]; 
    } 
} 
+0

UPDATE:旋轉到橫向時改變preferredDisplayMode到'UISplitViewControllerDisplayModeAutomatic'修復它,但是當在肖像,如果我點擊屏幕上駁回酥料餅,然後旋轉回景觀,主VC含量消失。 –

回答

2

感謝https://devforums.apple.com/message/1024928#1024928我明白了。

在動畫協調器的完成塊中,將preferredDisplayMode設置爲UISplitViewControllerDisplayModeAutomatic使其工作。

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator { 
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; 

    if (self.traitCollection.userInterfaceIdiom == UIUserInterfaceIdiomPad) { 
     BOOL isPortrait = size.height > size.width; 

     if (isPortrait) { 
      self.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay; 
     } 

     [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { 
      if (isPortrait) { 
       self.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay; 
      } 
      self.dividerView.hidden = isPortrait; 
     } completion:^(id<UIViewControllerTransitionCoordinatorContext> context) { 
      // ADD THIS TO THE COMPLETION BLOCK 
      self.preferredDisplayMode = UISplitViewControllerDisplayModeAutomatic; 

      NSLog(@"Preferred display mode: %ld | Actual display mode: %ld", self.preferredDisplayMode, self.displayMode); 
     }]; 
    } 
} 
+0

這工作!天才... –

相關問題