Detect when both the master and detail view controller are on screen?
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");
}
}
In swift:
func splitViewController(_ svc: UISplitViewController, willChangeTo displayMode: UISplitViewController.DisplayMode) {
if displayMode == .primaryHidden {
print("Detail is visible")
}
if displayMode == .allVisible {
print("Master and Detail are visible")
}
}
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 aDetailViewController
is zoomed to cover the full screen. If you really want to know if both are visible, check beside the.collapsed
property forsplitViewController.displayMode == UISplitViewControllerDisplayMode.AllVisible.
I found it useful when dealing with iPhone 6 Plus Landscape layouts.