【问题标题】:adaptivePresentationStyleForPresentationController is returning the wrong traitCollection on 6+AdaptivePresentationStyleForPresentationController 在 6+ 上返回错误的 traitCollection
【发布时间】:2016-02-17 11:00:07
【问题描述】:

我呈现的视图在水平尺寸类别为 Regular 时看起来像 popover,而在水平尺寸等级是Compact

效果很好,在带有 SplitView 的 iPad 上,它可以正确调整大小,并且在任何 not+ iphone 中都可以很好地作为弹出框,但在 iPhone 6+ 中,方法,

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

被调用了 3 次(仅在纵向模式下,在横向模式下正常工作),第一次返回一切正确(对于紧凑视图)但另外两次特征集合水平大小类被认为是常规的,所以它搞砸了我对视图执行的布局更新。

我想知道为什么这台设备会发生这种情况(正如我所说,在 iPad 中使用 SplitView 调整大小效果很好),以及它是否可以解决。可能是一个来自超级视图的问题,它迫使一个特征发生变化?

这是我的adaptivePresentationStyleForPresentationController 方法

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
}

事实证明,它在全屏模式下将视图呈现为模式视图,除了最后两次返回 .None,但我的 collectionViewLayout 会更新这些迭代。

提前致谢

【问题讨论】:

标签: ios swift autolayout iphone-6-plus


【解决方案1】:

我在另一个委托方法-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
    }
}

奇怪的是,我还没有观察到style 取值UIModalPresentationPopover

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-18
    • 1970-01-01
    • 1970-01-01
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多