我有一个 UIScrollView . 我给它做了一个轻击手势:
self.tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.tapped(_:)))
self.tapGesture.delegate = self
self.tapGesture.numberOfTapsRequired = 1
self.tapGesture.numberOfTouchesRequired = 1
self.tapGesture.cancelsTouchesInView = false
self.tapGesture.delaysTouchesBegan = false
self.tapGesture.delaysTouchesEnded = false
self.scrollView.addGestureRecognizer(self.tapGesture)
这工作正常,除非滚动视图滚动(滚动动画正在发生,而不是用户拖动),轻击手势将被忽略 .
我如何设置滚动视图的动画:
UIView.animate(withDuration: 0.3, delay: 0.0,
options:[.beginFromCurrentState, .curveEaseInOut], animations:
{
self.scrollView.contentOffset = CGPoint(x:self.scrollView.contentOffset.x, y:yOffset)
}, completion: nil)
这个滚动视图大部分时间滚动,我试图将它转到 recognize the tap gesture while scroll view is animating scrolling ....
1 回答
看一下UIGestureRecogniserDelegate函数 .
您应该能够使用以下功能指定可以同时识别平移和轻击手势:
注意:确保您的类符合UIGestureRecogniserDelegate协议,并将脚本设置为自我委托 .
这应该有效,但我现在无法完全测试它 .
UPDATE:
如果您在动画期间尝试识别水龙头,则可能需要在UIView.animateWithDuration的选项中使用
UIViewAnimationOptions.AllowUserInteraction
选项 . 使用其他answer作为来源