手势响应随着使用而变慢
我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可能有很多事情。我要做的第一件事是针对应用程序运行仪器并查找泄漏。像这样的速度减慢可能是由于创建对象但未释放对象造成的。另请注意,泄漏仪器并不能检测到所有内容。我经常通过查看分配情况并检查活动实例的正确数量来发现对象泄漏。
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.
问题解决了!事实证明,每次加载页面时我都会添加新的手势识别器,而不会删除以前的手势识别器。
Problem solved! It turns out I was adding new gesture recognisers each time a page was loaded without removing the previous ones.
我遇到了这个缓慢的segue问题,只有在滑动segue时才出现。我来到这个帖子,看到 @colincameron 的帖子,说他在每次加载时都堆叠了手势识别器。
所以我去找了这个 SO 线程,其中 @robmayoff 展示了如何从视图中删除所有手势识别器。您可以将此删除代码添加到您的prepareForSegue、viewDidDisappear 等
Swift 中,
该代码解决了我的缓慢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
That code solved my slow segue problem.