views:

89

answers:

1

I have put a line of code inside the UIAnimation block. And the next line comes after the animation block. I want the second line only to be executed after the time interval of the first animation block.

Eg:-

[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:0.5];
//First line comes here
 [self.view addSubview:subView];
 [UIView commitAnimations];

Then the 2nd line

[subView2 removeFromSuperView];

I want the 2nd line only to be executed after the 0.5 second interval of the animation action. Is it possible to do like this?

+1  A: 

You can set a delegate for animation and remove subview in its method:

...
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:0.5];

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

//First line comes here
[self.view addSubview:subView];
[UIView commitAnimations];
...

Then in delegate's animation did stop handler remove your 2nd subview:

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{
    if ([finished boolValue])
        [subView2 removeFromSuperview];
}
Vladimir