iOS:如何使手势识别器在动画发生时反应更快?
我在 UIViewController 页面中有 4 个子视图,排列为网格。有时,动画会在子视图上运行。我正在尝试识别其中一个子视图上的点击(使用 UITapGestureRecognizer)。
现在,当动画未运行时,可以顺利识别点击。但是,当动画运行时,我的大多数点击根本无法识别(即使动画在另一个子视图上运行时)。
有什么方法可以提高手势识别器比动画的优先级吗?任何建议表示赞赏。谢谢
I have 4 subviews in a UIViewController page arranged as a grid. Sometimes, animations will be running on the subviews. I am trying to recognize taps on one of the subviews (using UITapGestureRecognizer).
Now, the when animation is not running, taps are recognized smoothly. But, when an animation is running, most of my taps are not recognized at all (even when animation is running on another subview).
Is there any way to increase priority of the Gesture recognizer than the animation ? Any suggestions are appreciated. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该问题是由于将动画选项设置为 0 造成的。添加
UIViewAnimationOptionAllowUserInteraction
作为动画选项后,效果很好。The issue was due to setting animation options as 0. After adding
UIViewAnimationOptionAllowUserInteraction
as the animation option, it works nicely.这听起来是主线程被堵塞的典型案例。多线程将解决您的问题。
做这样的事情:
一旦你的动画在一个单独的方法中,你就可以自由地这样做:
这将使你的主线程自由地识别触摸事件: )
This sounds like a classic case of the main thread being clogged up. Multithreading will solve your problem.
Do something like this:
Once you have your animations in a separate method, you're free to do this:
This will leave your main thread free to recognize the touch events :)