Chelsea Shawra Chelsea Shawra - 1 month ago 14
iOS Question

How to swipe a View controller over the top of another view controller?

I have a table view controller and another view controller. Now my requirement is that i need to swipe the table view controller half over the another view controller when i swipe the view controller. The image i can show is like this:

enter image description here

Is it possible to achieve this by using the Swipegesture . If possible how can i do this in Swift3?

Rob Rob
Answer Source

While there are libraries out there to do this for you, if you are going to do this yourself, the basic idea is that you can create a "swipe from edge" gesture recognizer to initiate a custom presentation of a view controller (that has your menu on it). It consists of:

  • a custom transitioning delegate (a UIViewControllerTransitioningDelegate subclass) that specifies the animation controller and interaction controller (both described below) to be used during the presentation of the next scene;

  • an animation controller (a UIViewControllerAnimatedTransitioning subclass) that dictates the animation of the scene from the right edge;

  • an interaction controller (a UIPercentDrivenInteractiveTransition that you can drive from a gesture) to drive the animation if you want;

  • a presentation controller (a UIPresentationController subclass) that dictates whether the presented view will be removed or not (in this case you do not want it removed), as well as any other chrome to be animated alongside the animated presentation of the new scene (e.g. you often dim or blur the presenting view); and

  • gesture recognizers to drive the interaction controller.

For more information, see WWDC videos Custom Transitions Using View Controllers and A Look Inside Presentation Controllers.

See https://github.com/robertmryan/SwiftCustomTransitions/tree/rightside for a Swift 3 example that renders the following UX:

enter image description here

This is all admittedly complicated enough that you may well want to consider third party libraries for presenting slide-in menus. But if you wanted to "roll your own", these are the basic pieces involved.