UIPanGestureRecognizer with fade animation

So, I have a uiview inside my UIViewController. It looks something like this ... enter image description here

What I am trying to do with UIPanGestureRecognizer, when I scroll to the right or left (starting from any green line in the image and ending with another green line), the red view disappears, but with a fade out animation.

Here's what I've 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 ... Thanks!

+3


source to share





All Articles