some_id
some_id

Reputation: 29886

TableView interaction blocking animations in cells

I have a progress indicator in a tableview cell that does not update its progress while the user interacts with the tableview. When the interaction stops the indicator jumps to where it should be.

How can this be avoided so that the animations continue even if the user is scrolling the tableview?

Can they be added to a runloop? If both the interaction and the animating needs to happen on the main thread, what work around can be done?

Upvotes: 3

Views: 135

Answers (1)

redlightbulb
redlightbulb

Reputation: 1486

First, you should make sure you really do want those progress indicators to update - The default behavior with UIScrollView type classes when scrolling is to pause any UI updates within them to keep things responsive. I've found things like scrolling speed can degrade surprisingly quickly whenever I try to do anything extra, especially on older devices.

Warnings aside, how do we do this? Well it looks like this question has a solution for you. A brief summary is:

  • Scrolling puts the runloop in UITrackingRunLoopMode
  • Your update code is not triggering while the runloop is in this mode
  • Solution: Have an NSTimer trigger your progress indicator updates, run that timer in NSRunLoopCommonModes so it will still fire while scrolling.

That's it. UIView updating is not the issue while scrolling, running the code that triggers the update is. By using a timer that is 'scroll-proof', your indicators should update just fine. There is some good example code at the linked question, so do click through to read!

Upvotes: 3

Related Questions