简体   繁体   English

检测主视图控制器和详细视图控制器何时都在屏幕上?

[英]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 a DetailViewController 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 for splitViewController.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.

相关问题 iOS / Master Detail:从主控制器切换细节时,如何弹出子细节视图? - iOS / Master Detail : how to pop the subdetail view when switching detail from the master controller? 呈现UISplitViewController的主视图和详细视图 - Present a view over both the master and detail of a UISplitViewController 如果从明细视图控制器导航到新屏幕,如何隐藏主视图 - How to hide the master view if navigate to new screen from detail view controller 当详细信息视图控制器可见时,从主视图控制器中删除UIBarButtonItem - Remove UIBarButtonItem from master view controller when detail view controller is visible Swift 4 Split View Controller Detail取代Master - Swift 4 Split View Controller Detail Replaces Master 主细节应用程序初始视图控制器更改 - Master detail application initial view controller change 故事板,标签栏控制器和主视图/详细视图 - storyboards, tab bar controller and a master/detail view iPad主细节应用程序-更改细节视图控制器的内容 - iPad master detail app - change detail view controller's content 在对象库中找不到主视图控制器和详细视图控制器 - Master View Controller and Detail View Controller not found in Object Library 在主视图控制器项上更改明细视图控制器,单击UISplitViewController - Change Detail View controller on Master View controller item click UISplitViewController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM