您可以命名您的動畫(每個視圖都需要一個獨特的動畫名稱):
[UIView beginAnimations:@"myAnimation" context:nil];
myView.alpha = 1.0f; // or whatever property you're animating...
[UIView commitAnimations];
,然後在
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(id)context
{
if ([finished boolValue])
{
if ([animationID isEqualToString:@"myAnimation"])
[myView removeFromSuperview];
}
}
或檢索這個名字更好,但使用的iOS4 +塊動畫方法及其完成處理程序,您將能夠更完整地引用完成處理程序中正在動畫的視圖。例如
[UIView animateWithDuration:0.4f animations:^
{
myView.alpha=1.0f;
}
completion:^(BOOL finished)
{
[myView removeFromSuperview];
}];
我推薦使用基於塊的動畫和完成方法。 –