iOS:如何使手势识别器在动画发生时反应更快?

发布于 2024-10-16 04:53:54 字数 218 浏览 10 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏尔 2024-10-23 04:53:54

该问题是由于将动画选项设置为 0 造成的。添加 UIViewAnimationOptionAllowUserInteraction 作为动画选项后,效果很好。

The issue was due to setting animation options as 0. After adding UIViewAnimationOptionAllowUserInteraction as the animation option, it works nicely.

檐上三寸雪 2024-10-23 04:53:54

听起来是主线程被堵塞的典型案例。多线程将解决您的问题。

做这样的事情:

-(void)performAnimations{
    //Do your animations in this method
}

一旦你的动画在一个单独的方法中,你就可以自由地这样做:

[self performSelectorInBackground:@selector(performAnimations)];

这将使你的主线程自由地识别触摸事件: )

This sounds like a classic case of the main thread being clogged up. Multithreading will solve your problem.

Do something like this:

-(void)performAnimations{
    //Do your animations in this method
}

Once you have your animations in a separate method, you're free to do this:

[self performSelectorInBackground:@selector(performAnimations)];

This will leave your main thread free to recognize the touch events :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文