nicog
nicog

Reputation: 112

How to Swipe Away / Slide In a Side Menu In Swift?

In my app I've coded a side menu that looks like this: enter image description here

Here's the code that is called when I tap a menu button that's in some views: enter image description here

How can I have the menu slide in to view (depending on where the user's dragging finger is) and swipe away? And also go away when I tap the dimmed view on the right.

Any help is appreciated.

Upvotes: 0

Views: 1519

Answers (1)

BlackPearl12
BlackPearl12

Reputation: 316

One way to achieve this is using the gesture recognizers in swift.

  1. To tap and dismiss the menu control, use UITapGestureRecognizer, bind it with a selector method and dismiss the controller/ view you are presenting. Check out the link to apple documentation for TapGesture : Guide

  2. For swipe gesture, add Swipe gesture UISwipeGestureRecognizer to the UIView, and write the dismiss method using slide animation for smooth UI. Swipe Gesture Guide

Let me know if you need any more help.

Upvotes: 1

Related Questions