[英]Detect when both the master and detail view controller are on screen?
I have implemented a UISplitViewController
using a Universal Storyboard in Xcode 6. UISplitViewController
is supported on iPhone running iOS 8 now, and by default only one view controller will be on screen at a time.我已经在 Xcode 6 中使用 Universal Storyboard 实现了一个
UISplitViewController
。现在运行 iOS 8 的 iPhone 支持UISplitViewController
,并且默认情况下一次只有一个视图控制器会出现在屏幕上。
I need to know when both the master and detail view controllers are both on screen (iPad).我需要知道主视图控制器和细节视图控制器何时都在屏幕上(iPad)。 I need to remove the disclosure indicators from
UITableViewCell
s in the case both are on screen - only render them when only the master view controller is on screen (iPhone), just like the Settings app.如果两者都在屏幕上,我需要从
UITableViewCell
删除披露指示符 - 仅当只有主视图控制器在屏幕上(iPhone)时才呈现它们,就像设置应用程序一样。
I could simply detect the device and only add them if it's an iPhone, but that's not recommended.我可以简单地检测设备并仅在它是 iPhone 时添加它们,但不推荐这样做。 It's possible a new device would display only one view controller and not identify as a phone.
新设备可能只显示一个视图控制器,而不能识别为手机。 Another thought would be to detect if
self.splitViewController
is nil
, but that won't work because it won't be nil
on iPhone nor iPad because it actually is in a split view controller on iPhone.另一个想法是检测
self.splitViewController
是否为nil
,但这不起作用,因为它在 iPhone 或 iPad 上不会nil
,因为它实际上在 iPhone 上的拆分视图控制器中。
Is it possible to detect when both the master and detail view controller are visible on screen at the same time?是否可以检测到主视图控制器和详细视图控制器何时在屏幕上同时可见?
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.
当拆分视图控制器内容在语义上折叠到单个容器中时,此属性设置为 YES。 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.
折叠后,拆分视图控制器报告其 viewControllers 属性中只有一个子视图控制器。 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.
折叠时, displayMode 属性对拆分视图控制器界面的外观没有影响。
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 .
当拆分视图控制器能够同时显示它的两个子视图控制器时,该属性的值为 NO,即使它当时没有同时显示它们。 In this expanded mode, the split view controller's configuration of its child view controllers is determined by the displayMode property.
在这种扩展模式下,拆分视图控制器对其子视图控制器的配置由 displayMode 属性决定。 In addition, the viewControllers property contains both the primary and secondary view controllers.
此外,viewControllers 属性包含主视图控制器和辅助视图控制器。
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.
在从展开到折叠界面的转换过程中,此属性的值为 NO,直到折叠转换完成并且所有相关的委托方法都已被调用。 Similarly, when transitioning back to an expanded interface, the value is YES until the transition finishes.
类似地,当转换回扩展界面时,该值为 YES 直到转换完成。
from class reference.从类参考。
Thanks to Frederik A. Winkelsdorf:感谢 Frederik A. Winkelsdorf:
It should be noted that
.collapsed
also reports false if aDetailViewController
is zoomed to cover the full screen.应该注意的是,如果
DetailViewController
被缩放以覆盖全屏,.collapsed
也会报告 false。 If you really want to know if both are visible, check beside the.collapsed
property forsplitViewController.displayMode == UISplitViewControllerDisplayMode.AllVisible.
如果您真的想知道两者是否可见,请检查
splitViewController.displayMode == UISplitViewControllerDisplayMode.AllVisible.
的.collapsed
属性splitViewController.displayMode == UISplitViewControllerDisplayMode.AllVisible.
I found it useful when dealing with iPhone 6 Plus Landscape layouts.我发现它在处理 iPhone 6 Plus 横向布局时很有用。
This is the way to check Displaymode for UISplitViewController这是检查 UISplitViewController 的 Displaymode 的方法
- (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")
}
}
I found that using display mode wasn't working for me but these were.我发现使用显示模式对我不起作用,但这些是。
func primaryViewController(forExpanding splitViewController: UISplitViewController) -> UIViewController? {
return nil
}
func primaryViewController(forCollapsing splitViewController: UISplitViewController) -> UIViewController? {
return nil
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.