Detect when both the master and detail view controller are on screen?

懵懂的女人 提交于 2019-12-04 01:37:25

UISplitViewController

@property(nonatomic, readonly, getter=isCollapsed) BOOL collapsed

This property is set to YES when the split view controller content is semantically collapsed into a single container. Collapsing happens when the split view controller transitions from a horizontally regular to a horizontally compact environment. After it has been collapsed, the split view controller reports having only one child view controller in its viewControllers property. The other view controller is collapsed into the other view controller’s content with the help of the delegate object or discarded temporarily. When collapsed, the displayMode property has no impact on the appearance of the split view controller interface.

The value of this property is NO when the split view controller is capable of displaying both of its child view controllers at the same time, even if it is not showing them both at the moment. In this expanded mode, the split view controller’s configuration of its child view controllers is determined by the displayMode property. In addition, the viewControllers property contains both the primary and secondary view controllers.

During a transition from an expanded to collapsed interface, the value of this property is NO until after the collapse transition finishes and all of the relevant delegate methods have been called. Similarly, when transitioning back to an expanded interface, the value is YES until the transition finishes.

from class reference.

Thanks to Frederik A. Winkelsdorf:

It should be noted that .collapsed also reports false if a DetailViewController is zoomed to cover the full screen. If you really want to know if both are visible, check beside the .collapsed property for splitViewController.displayMode == UISplitViewControllerDisplayMode.AllVisible. I found it useful when dealing with iPhone 6 Plus Landscape layouts.

This is the way to check Displaymode for UISplitViewController

- (void)splitViewController:(UISplitViewController *)splitViewController willChangeToDisplayMode:(UISplitViewControllerDisplayMode)displayMode {
  if (displayMode == UISplitViewControllerDisplayModePrimaryHidden) {
       NSLog(@"Detail view is visible");
} else if (displayMode == UISplitViewControllerDisplayModeAllVisible) {
       NSLog(@"both are visible");
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!