Search code examples
iosmultithreadinganimationcore-animation

Simultaneous animations block each other


Our iPad app has a main UIViewController's view which contains on top several subviews with their own tasks, they contain uitableviews, image galleries, graphs and tickers. We've also make sure every subview as its own controller class to manage animations and user interaction.

The problem is that animations block each other, every time we interact with a tableView, the ticker and gallery (which also has automatic animations)freeze.

What approach can we try for simultaneous animations? Should we try directly using layers with core animation or perform all animations in the same animation block?

Thanks.


Solution

  • Here's some useful code:

    // We schedule a timer for a desired 30fps animation rate.
    // In performAnimation: we determine exactly
    // how much time has elapsed and animate accordingly.
    timer = [[NSTimer scheduledTimerWithTimeInterval:(1.0/30.0) target:self selector:@selector(performAnimation:) userInfo:nil repeats:YES] retain];
    
    // The next two lines make sure that animation will continue to occur
    // while modal panels are displayed and while event tracking is taking
    // place (for example, while a slider is being dragged).
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSModalPanelRunLoopMode];
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSEventTrackingRunLoopMode];