我正在尝试循环多个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:)];