Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is -animateWithDuration:delay:options:animations:completion: blocking the UI?

I always thought that Core Animation performs animations on the background. When I run this code, my UI interactions are blocked until the animation finishes:

[UIView animateWithDuration:4.5 
                      delay:0 
                    options:options 
                 animations:^{
                    oldView.alpha = 0;
                    newView.alpha = 1;
                 }  
                 completion:^(BOOL finished) {
                    if (finished) {
                        [oldView removeFromSuperview];
                    }
                 }];

Like you can see the duration is long so it's clearly visible that the UI interactions are blocked while animating.

The UI interaction begins to be blocked when the animation begins, and ends to be blocked when the animation finishes.

Is there a way to start a UIView animation concurrently so the UI interactions are not blocked?

EDIT to clarify: I know that the UI is blocked because I cannot interact with any control on the screen why this animation is running. Those other controls are not related with what is being animated and are not on the same branch in the view hierarchy. The entire UI is blocked when this animation runs. When I set it to 10 seconds, the UI is blocked for 10 seconds while the animation runs. Tested with iOS 4.2 on iPhone 4.

like image 457
Proud Member Avatar asked Apr 01 '12 19:04

Proud Member


1 Answers

Looking at the documentation for UIView, I found this in the discussion section for that method:

During an animation, user interactions are temporarily disabled for the views being animated. (Prior to iOS 5, user interactions are disabled for the entire application.) If you want users to be able to interact with the views, include the UIViewAnimationOptionAllowUserInteraction constant in the options parameter.

So, if you want user interaction to continue to be allowed, you must set this constant in the options parameter.

like image 148
jmstone617 Avatar answered Sep 22 '22 11:09

jmstone617