UINavigationController Inside a Popover

Noah Gilmore wrote about his approach to use UINavigationController inside a popover without subclassing the navigation controller. Even though I don’t work on iOS apps, like, at all these days, this sounds too useful to go by unnoticed.

Hopefully this was a helpful look into the world of preferredContentSize, view controller wrapping, and UIKit popovers. Here’s a tl;dr:

  • To define the size of your popover with autolayout, set preferredContentSize to the result of systemLayoutSizeFitting
  • To animate popover size updates at the same time as navigation controller animations, wrap your UINavigationController in a PopoverPushController (see code below)
  • When you change your controller’s preferredContentSize, be sure to change the preferredContentSize of your controller’s popoverPresentationController’s presentedViewController as well

See NGPopoverForceResizeTest, the resulting sample app on GitHub.