So i have an uiview inside my UIViewController. It looks something like this...

What i'm trying to do is, with an UIPanGestureRecognizer, that when i swipe to the right or to the left (starting at any green line in the image, and finishing in the other green line) the red view disappears, but with an animation of fadeout.
This is what i have tried...
let gestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePan(gestureRecognizer:)))
myview.addGestureRecognizer(gestureRecognizer)
func handlePan(gestureRecognizer: UIPanGestureRecognizer) {
if gestureRecognizer.state == .began {
UIView.animate(withDuration: 0.5, delay: 0.5, options: UIViewAnimationOptions.curveEaseOut, animations: {
//maybe this code works.??
}, completion: nil)
}
if gestureRecognizer.state == .changed {
let translation = gestureRecognizer.translation(in: self.view)
//something with translation .x and .y values??
}
}
But i'm not sure how to achieve my goal. If you can help me... Thank you!!!