如何在视图animation时识别点按手势

只是想知道是有办法让视图识别轻拍手势,而它正在animation? 我正在研究一个有连接到它的cashapelayer线的视图。 当用户平移视图(平移手势)时,线将相应地跟随直到用户停止平移。 此时将执行一个animation,将视图恢复到原来的位置,同时系绳层也回到原位。 现在我唯一真正的问题是,虽然视图和系绳是animation视图不响应轻拍手势…

任何人都知道一些技巧? 我希望我的解释是可以理解的,并提前感谢!

(如果系统视图的概念不清楚,有一个免费的应用程序称为discovr应用程序将举一个例子)。

我假设你正在使用[UIView animateWithDuration: delay: options: animations: completion:]; animation的方法。

如果是这样,您需要传递UIViewAnimationOptionAllowUserInteraction作为选项,以使animation视图在animation时响应触摸。

你需要设置两个选项 – UIViewAnimationOptionAllowUserInteractionUIViewAnimationOptionAllowAnimatedContent 。 首先让您在animation过程中与视图进行交互,第二种方法是在每一帧animation上重新绘制视图,而不使用开始和结束帧的快照。

(Swift 3)通过.allowUserInteraction选项

 UIView.animate(withDuration: 0.75, delay: 0.0, options: [.allowUserInteraction], animations: { // Desired animation(s) }, completion: { (finished: Bool) in // Completion })