【发布时间】:2012-05-16 05:12:43
【问题描述】:
我正在尝试遍历多个 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:)];
【问题讨论】:
标签: animation uiview core-animation uiviewanimation catransaction