我试图遍历多个UIViews
和各执行动画,但我想知道,当所有的动画已经完成。 什么是调用函数时动画的循环已经结束的最好方法? 或者,有没有办法等到所有已经完成?
我试着用setAnimationDidStopSelector
,但它不火。 在这种情况下,我通过让他们淡出然后遭到移除清除一些“筹码”关游戏板(NumberedChipView是的UIView的子类)。 游戏无法继续,直到芯片了董事会。
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate: self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop)];
// clear chips
for (HexagonalTile *aTile in tilesToClear) {
NumberedChipView *chipView = [self chipViewForColumn:aTile.column andRow:aTile.row];
[UIView animateWithDuration:0.5 delay:0.3 options:UIViewAnimationCurveLinear animations:^{
chipView.alpha = 0.0;
}
completion:^(BOOL finished){
if (finished) {
[chipView removeFromSuperview];
[self.chipViews removeObject:chipView];
}
}];
}
[UIView commitAnimations];
我也试过CATransaction
无济于事:
[CATransaction begin];
[CATransaction setCompletionBlock:^{
[self animationFinished];
}];
// clear chips
for (HexagonalTile *aTile in tilesToClear) {
NumberedChipView *chipView = [self chipViewForColumn:aTile.column andRow:aTile.row];
[UIView animateWithDuration:0.5 delay:0.3 options:UIViewAnimationCurveLinear animations:^{
chipView.alpha = 0.0;
}
completion:^(BOOL finished){
if (finished) {
[chipView removeFromSuperview];
[self.chipViews removeObject:chipView];
//NSLog(@"clearing finished");
}
}];
}
[CATransaction commit];
更新:
我现在可以得到选择火,但它不等待动画完成的循环。
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:)];