I'm having the hardest time implementing a presentation of a drawer sliding partway up on the screen on iPhone.
EDIT: I've discovered that iOS is not respecting the .custom modalTransitionStyle I've set in the Segue. If I set that explicitly in prepareForSegue:
, then it calls my delegate to get the UIPresentationController
.
I have a custom Segue that is also a UIViewControllerTransitioningDelegate. In the perform()
method, I set the destination transitioningDelegate to self:
self.destination.transitioningDelegate = self
and I either call super.perform()
(if it’s a Present Modal or Present as Popover Segue), or self.source.present(self.destination, animated: true)
(if it’s a Custom Segue, because calling super.perform()
throws an exception).
The perform()
and animationController(…)
methods get called, but never presentationController(forPresented…)
.
Initially I tried making the Segue in the Storyboard "Present Modally" with my custom Segue class specified, but that kept removing the presenting view controller. I tried "Present as Popover," and I swear it worked once, in that it didn't remove the presenting view controller, but then on subsequent attempts it still did.
So I made it "Custom," and perform()
is still being called with a _UIFullscreenPresentationController
pre-set on the destination view controller, and my presentationController(forPresented…)
method is never called.
Other solutions dealing with this issue always hinge on some mis-written signature for the method. This is mine, verbatim:
public func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController?
I've spent the last four days trying to figure out “proper” custom transitions, and it doesn't help that things don’t seem to behave as advertised. What am I missing?
Instead of using a custom presentation segue, you could use a
Container View
for your drawer. This way, you can use a UIViewController for your Drawer content, while avoiding the issue with the custom segue.You achieve this in two steps: First pull a Container View into your main view controller and layout it properly. The storyboard would look like this: (You can see you have two view controllers. One for the main view and one for the drawer)
Second, you create an action that animates the drawer in and out as needed. One simple example could look like this:
Here, I simply change the height constraint of the drawer, to slide it in and out. Of course you could do something more fancy :)
You can find a demo project here.