How to push a ViewController as a Popover

As the title suggests, I would like to push a ViewController onto the navigation stack, not full screen but as a popover, but despite setting the modalPresentationStyle to .popover at various positions I can't get it to work, it is still presented in full screen.
If I use present(vc, ani, comp) it works, but not with pushing.

For clarity, it should look like the iOS Clock or Calendar app, when you add an alarm or create a new event.

Replies

You cannot "push" a view controller as a different presentation style because it is not a presentation. In general, when we talk about UINavigationController and "push", it refers to the stack of view controllers that are transitioned from right-to-left when pushed, and left-to-right when popped.

If the behaviour of Clock and Calendar that I think you are referring is the sheet presentation that comes up that when creating a new Alarm that will allows content to be pushed, then you should present the a UINavigationController that wraps the view controller you are trying to present.

Code Block swift
/* Instead of: */
self.present(destinationViewController, animated: true, completion: nil)
/* You should instead: */
self.present(UINavigationController(rootViewController: destinationViewController), animated: true, completion: nil)

This then allows you to have a navigation stack to push/pop in the presented hierarchy.
You need a custom UIViewControllerAnimatedTransitioning, use it to create a custom animation for push