Ios 循环数组:对每个元素执行一个操作,但在操作完成后只执行一个回调

Ios 循环数组:对每个元素执行一个操作,但在操作完成后只执行一个回调,ios,objective-c,cocos2d-iphone,Ios,Objective C,Cocos2d Iphone,我使用UIPangestureRecognitor来检测PAN/滑动。当刷卡完成且触摸结束时,我在NSSet中的12个CCNodeColor上运行CCAction 当CCActions运行时,我禁用了uipangestureerecognizer,这样用户就不能在上一个动画仍在运行时滑动。完成操作后,我再次启用UIPangestureRecognitor 问题:*回调操作运行12次。因此,在其他11项操作完成之前,UIPangestureRecognitor已启用。只有在最后一个动作*移动完成后

我使用UIPangestureRecognitor来检测PAN/滑动。当刷卡完成且触摸结束时,我在NSSet中的12个CCNodeColor上运行CCAction

当CCActions运行时,我禁用了uipangestureerecognizer,这样用户就不能在上一个动画仍在运行时滑动。完成操作后,我再次启用UIPangestureRecognitor

问题:*回调操作运行12次。因此,在其他11项操作完成之前,UIPangestureRecognitor已启用。只有在最后一个动作*移动完成后才运行*回调的最佳方法是什么

还是这是个问题

以下是简化代码:

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];
    }
}

这里有一个“简化”的可能答案

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];

}