2

I would like to adapt between two different UIPresentationController, according to the current trait collection. For example, the two controllers could be UIPopoverPresentationController for any traits and a custom UIPresentationController for compact horizontal traits (e.g. iPhone).

Unfortunately this doesn't seem possible in the latest iOS 8. In particular:

  • You can set a UIAdaptivePresentationControllerDelegate to swap out the presentation style, but only permits the standard full screen presentation controller.

  • You can choose which presentation controller to use just before presenting the view controller, but this doesn't actually adapt after presenting when the traits collection changes e.g. in iPad multitasking or orientation change.

A couple of different attempts at a solution: Tumblr, Irace

Any suggestions?

Glen Low
  • 4,379
  • 1
  • 30
  • 36

1 Answers1

0

To assume you require two presentation controllers for adaptation is a false assumption.

There is only one presentation controller and you have to adapt the view and/or the transition using the delegate methods. For the custom transition you simply set a transition delegate class on the view controller you return from viewControllerForAdaptivePresentationStyle which in my case was a navigation controller with a transparent dimmed view with table at bottom and done button in the right nav item. My custom transition moves the table up from the bottom, while dimming and resizing the dimmed view, and fading in the nav bar. If you would like to see the behaviour yourself run Maps and tap the bottom right info button and try it on iPhone and iPad, I've copied that exactly. Here are screenshots of compact and regular: enter image description here enter image description here

malhal
  • 26,330
  • 7
  • 115
  • 133
  • So do you set a popover presentation controller as your presentation controller? Or are you using a custom presentation controller to accomplish this? – atreat Jan 03 '18 at 21:07
  • Yes popover. This might help: https://useyourloaf.com/blog/making-popovers-adapt-to-size-classes/ – malhal Jan 03 '18 at 22:14
  • Can you share sample code for this? Trying to figure this out as well. Did you subclass UIPopoverPresentationController and it adapts itself? – Maximilian Litteral Jun 24 '19 at 10:54