Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

completion block of uiview animate never called if view disappear

i noticed some strange behavior. When i start a animation and change the View (the view will not dismissed!), the completion handler never get called.

[UIView animateWithDuration:0.1f 
                          delay:0.0f 
                        options:UIViewAnimationCurveEaseOut 
                     animations:^(void){
                         [myView setHidden:YES];
                         myLabel.alpha = 0.0f;
                         someOtherView.frame = CGRectMake(130, bubbleBigRect.origin.y, 61, 65);
                         [button setHidden:YES];
                     } 
                     completion:^(BOOL finished){
                         NSLog(@"Complete %d",finished);
                         [imageVIew setImage:[UIImage imageNamed:@"myPng.png"]];                    
                     }];
}

is there any solution for this?

like image 230
bopa Avatar asked Jan 30 '12 11:01

bopa


2 Answers

Don't know where to write it, but I get the same thing that you have, but in my case the completion block was sometimes called. It might be same thing.
I found out that if in the animation block has nothing was animate- for example, if you set alpha=0 to uiview that is alpha is already 0, or you set content offset to UIScrollView to the same content offset (like in my case), the completion block not called.

like image 95
shem Avatar answered Nov 15 '22 21:11

shem


Put this in your animation block, and put everything you want to do on completion in YOUR_SELECTOR method. You can now do whatever you want with your view and still have a way of executing something on completion!

[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(YOUR_SELECTOR)];
like image 28
Aurelien Porte Avatar answered Nov 15 '22 22:11

Aurelien Porte