所以我在UIViewController中有一个uiview。它看起来像这样......
我想要做的是,使用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??
}
}
但我不确定如何实现我的目标。 如果你能帮助我......谢谢!!!