我将展示一个视图,当水平大小类是正则的时,它看起来像一个弹出窗口,当水平大小类是紧凑的时,它看起来像一个模态视图。
它工作得很好,在带有SplitView的iPad上,它可以正确地调整大小,在任何情况下,iphone都可以像popover一样工作,但在iphone 6+上,这种方法,
表示控制器的自适应表示方式(控制器:UIPresentationController,traitCollection:uiRaitCollection)->UIModalPresentationStyle
称为三次(仅在纵向模式下,在横向模式下正常工作),第一次返回所有正确的内容(对于紧凑视图),但其他两次trait collection horizontal size类被认为是常规的,因此它会扰乱我在视图上执行的布局更新。
我想知道为什么这种情况会发生在这个设备上(正如我所说,在iPad中使用SplitView调整大小非常有效),以及它是否是一种解决方法。从一个超级观点来看,这可能是一个问题,迫使一个特质改变?
这是我的代表控制方法

public func adaptivePresentationStyleForPresentationController(controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {

  if controller.presentedViewController is ColorPickerCollectionViewController {
    colorPickerVC.collectionView?.setCollectionViewLayout(colorPickerFlowLayout(traitCollection), animated: true)
  }

  return (traitCollection.horizontalSizeClass == .Compact) ? .FullScreen : .None
}

结果显示,除了最后两次返回的视图外,它还以全屏模式将视图显示为模式视图。无,但我的collectionViewLayout更新了那些迭代。
提前谢谢

最佳答案

我在使用另一个委托方法时运气更好,-presentationController:willPresentWithAdaptiveStyle:transitionCoordinator:。我在试验:

- (void)presentationController:(UIPresentationController *)presentationController willPresentWithAdaptiveStyle:(UIModalPresentationStyle)style transitionCoordinator:(nullable id<UIViewControllerTransitionCoordinator>)transitionCoordinator {
    if ([presentationController isKindOfClass:[UIPopoverPresentationController class]] && style == UIModalPresentationNone) {
        // popover!
    } else {
        // not popover
    }
}

奇怪的是,我还没有观察到取这个值。

关于ios - adaptivePresentationStyleForPresentationController在6+上返回错误的traitCollection,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35454781/

10-09 16:14
查看更多