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