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
preferredContentSizeto the result ofsystemLayoutSizeFitting- To animate popover size updates at the same time as navigation controller animations, wrap your
UINavigationControllerin aPopoverPushController(see code below)- When you change your controller’s
preferredContentSize, be sure to change thepreferredContentSizeof your controller’spopoverPresentationController’spresentedViewControlleras well
See NGPopoverForceResizeTest, the resulting sample app on GitHub.