0

I have an OpenGL animation drawing on the main window fired by an NSTimer. If I bring up a popover window with a scrollable UITableView menu, the animation freezes while scrolling is in process. Once the scrolling animation stops, the timer callbacks start again. Its only when the user actively tries to scroll that the main window stops updating.

It seems like Apple's scroll animation is somehow blocking dispatch on the main loop. Is this true and is there a way to fix it?

I dont really want to introduce multithreading if I can help it because that will exponentially increase the complexity of my code.

Also I tried using CADisplayLink instead of NSTimer and the display link calls are also blocked by the scrolling animation.

Robotbugs
  • 4,307
  • 3
  • 22
  • 30
  • 4
    Apple’s #1 priority is UI responsiveness, and so in situations like this, UI actions will block other parts of your code. You need to move your timer to another thread. – bdesham Mar 13 '13 at 23:00
  • Do you have to do the animation with a timer? Why not use UIView animateWithDuration? – Rich Schonthal Mar 14 '13 at 00:26
  • Its for animation of OpenGL drawing, not of a view. – Robotbugs Mar 14 '13 at 22:02
  • UI is thread#1 and should never be blocked. Before answering your question, you have to decide what should be on thread#1: the animation or the scrolling. You will have to move one of them to another thread. But decide first and we can help. – Khaled Barazi Mar 15 '13 at 00:55

2 Answers2

0

As answered by bdesham, "Apple’s #1 priority is UI responsiveness, and so in situations like this, UI actions will block other parts of your code. You need to move your timer to another thread."

Robotbugs
  • 4,307
  • 3
  • 22
  • 30
0

NSTimer are tied to a run loop and mode. During event tracking, the mode is UITrackingRunLoopMode. By default, timers created by scheduledTimerWithTimeInterval are added with NSDefaultRunLoopMode and so do not fire during tracking.

[[NSRunLoop currentRunLoop] addTimer:yourTimer forMode:UITrackingRunLoopMode];
drawnonward
  • 53,459
  • 16
  • 107
  • 112