手势响应随着使用而变慢

发布于 2024-12-25 20:27:10 字数 239 浏览 1 评论 0原文

我正在使用 UIGestureRecognizer 来检测应用程序中的点击或滑动并更改页面。

经过一些使用(可能加载 50 个奇数页面)后,应用程序对手势的响应开始明显变慢。您可以点击并等待一整秒,以便识别该手势。

我检查了我的代码,并不是翻页速度变慢,因为通过其他方式(蓝牙键盘)仍然可以工作。按钮和菜单的响应也不会减慢。

有谁知道可能是什么原因造成的?它最终会导致应用程序变得无法使用。

I am using UIGestureRecognizer to detect taps or swipes and change page in my app.

After some use (perhaps 50 odd page loads) the app starts to respond noticeably slower to gestures. You can tap and wait a full second for the gesture to be recognised.

I have checked my code and it is not the page turning that is slowing down, as that still works by other means (bluetooth keyboard). Also the response of buttons and menus does not slow down.

Does anyone know what might be causing this? It eventually causes the app to become unusable.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

不一样的天空 2025-01-01 20:27:10

可能有很多事情。我要做的第一件事是针对应用程序运行仪器并查找泄漏。像这样的速度减慢可能是由于创建对象但未释放对象造成的。另请注意,泄漏仪器并不能检测到所有内容。我经常通过查看分配情况并检查活动实例的正确数量来发现对象泄漏。

There could be quite a few things. The first thing I would do is run instruments against the app and look for leaks. A slow down like this could be caused by objects being created and not released. Also note that the leaks instrument does not pick up everything. I've often picked up on objects leaking by looking at the allocations and checking that the correct number of instances are alive.

前事休说 2025-01-01 20:27:10

问题解决了!事实证明,每次加载页面时我都会添加新的手势识别器,而不会删除以前的手势识别器。

Problem solved! It turns out I was adding new gesture recognisers each time a page was loaded without removing the previous ones.

我是男神闪亮亮 2025-01-01 20:27:10

我遇到了这个缓慢的segue问题,只有在滑动segue时才出现。我来到这个帖子,看到 @colincameron 的帖子,说他在每次加载时都堆叠了手势识别器。

所以我去找了这个 SO 线程,其中 @robmayoff 展示了如何从视图中删除所有手势识别器。您可以将此删除代码添加到您的prepareForSegue、viewDidDisappear 等

Swift 中,

subview.gestureRecognizers?.forEach(subview.removeGestureRecognizer)

该代码解决了我的缓慢segue 问题。

I was having this slow segue problem, only when swiping for the segue. I came to this thread and saw the post from @colincameron saying that he was stacking gesture recognizers with each load.

So I went and found this SO thread, where @robmayoff shows how to remove all gesture recognizers from a view. You could add this removal code to your prepareForSegue, viewDidDisappear, etc

Swift

subview.gestureRecognizers?.forEach(subview.removeGestureRecognizer)

That code solved my slow segue problem.

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