2010-05-26 66 views
1

我已经把一行代码放入了UIAnimation块。下一行在动画块之后。我希望第二行仅在第一个动画块的时间间隔后执行。如何仅在动画块的时间间隔后执行一行代码?

例如: -

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

然后,第二线

[subView2 removeFromSuperView]; 

我想要的第二线只有动画动作的0.5秒的时间间隔之后执行。有没有可能这样做?

回答

2

您可以设置一个委托动画,并在其方法删除子视图:

... 
[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]; 
... 
在委托的动画没有停止处理程序删除您的第二子视图

然后:

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