我使用UIPanGestureRecognizer来检测平移/滑动。滑动完成并且触摸结束时,我在NSSet中的12个CCNodeColors上运行CCAction。
当CCActions正在运行时,我禁用UIPanGestureRecognizer,以便用户在上一个动画仍在运行时无法滑动。 CCActions完成后,我再次启用UIPanGestureRecognizer。
问题: *callback
操作运行12次。因此,在完成其他11个操作之前启用UIPanGestureRecognizer。在最后一次操作*callback
完成后仅运行*move
的最佳方式是什么?
(或者它是一个问题吗?)
以下是简化代码:
if (sender.state == UIGestureRecognizerStateEnded ) {
sender.enabled = NO;
for (CCNodeColor *node in nodeSet) {
CCActionMoveTo *move = [CCActionMoveTo actionWithDuration:1.0 position:newPosition];
CCActionCallBlock *callback = [CCActionCallBlock actionWithBlock:^{
sender.enabled = YES;
}];
CCActionSequence *seq = [CCActionSequence actionWithArray:@[move, callback]];
[node runAction:seq];
}
}
答案 0 :(得分:0)
这是一个简化的'可能的答案
if (sender.state == UIGestureRecognizerStateEnded ) {
sender.enabled = NO;
for (CCNodeColor *node in nodeSet) {
CCActionMoveTo *move = [CCActionMoveTo actionWithDuration:1.0 position:newPosition];
[node runAction:move];
}
CCActionDelay *wait = [CCActionDelay actionWithDuration:1.05f];
CCActionCallBlock *callback = [CCActionCallBlock actionWithBlock:^{
sender.enabled = YES;
}];
CCActionSequence *seq = [CCActionSequence actionWithArray:@[wait, callback]];
[self runAction:seq];
}