具有淡出动画的UIPanGestureRecognizer

时间:2017-08-08 01:12:47

标签: ios swift uipangesturerecognizer

所以我在UIViewController中有一个uiview。它看起来像这样...... enter image description here

我想要做的是,使用UIPanGestureRecognizer,当我向右或向左滑动(从图像中的任何绿线开始,并在另一条绿线中完成)时,红色视图消失,但是有一个淡出的动画。

这就是我试过的......

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??
    }
}

但我不确定如何实现我的目标。 如果你能帮助我......谢谢!!!

0 个答案:

没有答案