f0rz
f0rz

Reputation: 1565

Do something when animation is ready.

I have a animation in my navigationbased application.

[UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:1.5];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown 
                                       forView:self.view cache:YES];        
        [UIImageView commitAnimations];

Directly after this bit of code i call

[self.navigationController popViewControllerAnimated:NO];

The thing is, I don't want to pop my ViewController before my animation is ready.

Upvotes: 1

Views: 528

Answers (2)

Tom Irving
Tom Irving

Reputation: 10069

You can set a selector to be called when the animation is finished:

[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

And in that selector call the pop the view controller.

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {

       // Pop the controller now
    }

Upvotes: 1

Vladimir
Vladimir

Reputation: 170839

Set animations delegate and didStop selector and pop your view controller in that didStop method you specify:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown 
                                       forView:self.view cache:YES];        
[UIImageView commitAnimations];

Note, that didStop selector must be of the form specified in docs (see + setAnimationDidStopSelector method in docs for more details):

selector should be of the form: - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context.

Upvotes: 2

Related Questions