-2

I have a UIView which displays a warning to the user and appears at the top of my UIViewController. I'd like the user to be able to dismiss this warning by swiping it up/left/right. How can I achieve that without using a third-party library?

Everything I've found so far searching is related to making a UIViewController dismissible. I don't see a point in creating a separate ViewController off this little view.

Omid Ariyan
  • 1,164
  • 13
  • 19
  • Possible duplicate of [In iOS, how to drag down to dismiss a modal?](https://stackoverflow.com/questions/29290313/in-ios-how-to-drag-down-to-dismiss-a-modal) – Lefteris Oct 02 '18 at 09:56
  • @Lefteris You have given me a negative vote without carefully reading my question. The question you've assumed to be a duplicate of mine relates to a UIViewController and not a UIView as is mine. – Omid Ariyan Oct 02 '18 at 10:03
  • 1
    First of all I didn't give a negative vote, someone else did. Second I only suggested this as a possible duplicate. – Lefteris Oct 02 '18 at 10:06
  • Also if you only want to dismiss the UIView without any Interactive Animations, then all you need is to add a Gesture Recognizer to that View and dismiss it when the gesture fires – Lefteris Oct 02 '18 at 10:07
  • @Lefteris Apologies for assuming you've been the one whose given me a negative vote. That's the part I'm not sure how to achieve i.e. "Dismissing" the view. The way it should work is if the user swipes the view halfway, it should move with the finger but not be dismissed until the user removes their finger after which it continues to leave the scene. That's what I've witnessed to be the expected behaviour. – Omid Ariyan Oct 02 '18 at 10:11
  • @OmidAriyan - start by searching for `swift drag uiview` ... you'll find lots of examples and tutorials. Go through a couple so you understand the process. Then you'll want to add code to figure out if the view has been dragged up, left or right, and add an animation to continue its path off the screen. – DonMag Oct 02 '18 at 12:40
  • @DonMag That was actually helpful! Thanks :) – Omid Ariyan Oct 02 '18 at 15:45

1 Answers1

0

You could add a pan gesture recognizer or simply just a swipe gesture recognizer to achieve that. let gestureRecognizer = UISwipeGestureRecognizer(.....) view.addGestureRecognizer(gestureRecognizer)

Omair Ahmed
  • 119
  • 1
  • 10
  • Thank you for answering! The part I am not sure how to implement is "Dismissing" the view itself. The way it should work is if the user swipes the view halfway, it should move with the finger but not be dismissed until the user removes their finger after which it continues to leave the scene. – Omid Ariyan Oct 02 '18 at 15:44