1

I'm presenting a view that will look like a popover when the horizontal size class is Regular and like a modal view when the horizontal size class is Compact.

It works great, on the iPad with SplitView it resizes correcty and in any not+ iphone works great as a popover, but in the iPhone 6+, the method,

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

is called three times (only in portrait mode, in landscape mode works properly), the first time returns everything right (for the compact view) but the other two times the trait collection horizontal size class is considered regular so it mess up the layout update I perform over the view.

I wonder why this is happening in this device (as I said resizing with SplitView in iPad works great) and if it may be a workaroud it. May it be an issue comming from a super view that is forcing a trait change?

This is my adaptativePresentationStyleForPresentationController method

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
}

It turns out that it presents the view as a modal view, in FullScreen mode, besides the last two times it returns .None, but my collectionViewLayout gets updated those iterations.

Thanks in advance

fray88
  • 820
  • 1
  • 7
  • 23
  • Check this post: http://stackoverflow.com/questions/26687017/ios-8-presentationcontroller-determine-if-really-is-popover/37180653#37180653 – Slyv May 12 '16 at 08:03

1 Answers1

0

I've had better luck with another delegate method, -presentationController:willPresentWithAdaptiveStyle:transitionCoordinator:. I'm experimenting with:

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

Oddly, I have yet to observe style taking the value UIModalPresentationPopover.

nolanw
  • 475
  • 2
  • 14