colincameron
colincameron

Reputation: 2704

Gesture response slows with use

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.

Upvotes: 1

Views: 1657

Answers (3)

Dave
Dave

Reputation: 12216

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.

Upvotes: 1

colincameron
colincameron

Reputation: 2704

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

Upvotes: 3

drekka
drekka

Reputation: 21883

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.

Upvotes: 3

Related Questions