Cocoa CoreAnimation:在检查是否已结束时感到困惑

Cocoa CoreAnimation:在检查是否已结束时感到困惑,cocoa,core-animation,viewanimator,Cocoa,Core Animation,Viewanimator,我有一堆NSView子视图,它们被布置在网格中。用户可以围绕网格拖动子视图,在鼠标悬停时,我重新排列子视图,将拖动的视图插入网格上的关闭点 执行此操作的代码如下所示: for(int x=0; x<[pagesToMoveLeft count]; x++) { //get a grid location NSRect thisSubviewFrame = NSRectFromString([subviewCoords objectAtIndex:x]); //

我有一堆NSView子视图,它们被布置在网格中。用户可以围绕网格拖动子视图,在鼠标悬停时,我重新排列子视图,将拖动的视图插入网格上的关闭点

执行此操作的代码如下所示:

for(int x=0; x<[pagesToMoveLeft count]; x++) { 

    //get a grid location
    NSRect thisSubviewFrame = NSRectFromString([subviewCoords objectAtIndex:x]);

    //get the view to move
    NSView* viewToMove = [pagesToMoveLeft objectAtIndex:x];
    [[viewToMove animator] setFrame: thisSubviewFrame];

}
第一个是移动当前位置后的帧,第二个是它们的初始位置。看看每个数组中的项目2,它们都应该是220和25。而现在的数字是29,25。这是我拖动的视图,我将它从第二个位置移动到第一个位置附近25,25。29是我鼠标移动的地方…动画工作,视图2捕捉到25,25位置,视图1移动到视图2位置

我认为动画比代码慢,这就是为什么我在mouseUp上得到位置,而不是动画结束。我看了CoreAnimation文档,认为我需要使用类似animationDidStop的东西,但不确定如何实现它

任何帮助都将不胜感激

编辑:

我想出来了-

...
for(int x=0; x<[pagesToMoveLeft count]; x++) { 

        //get a grid location
        NSRect thisSubviewFrame = NSRectFromString([subviewCoords objectAtIndex:x]);

        //get the view to move
        viewToMove = [pagesToMoveLeft objectAtIndex:x];

        CAAnimation *animation = [[viewToMove animationForKey:@"frameOrigin"] copy];
        [viewToMove setAnimations:[NSDictionary dictionaryWithObject:animation forKey:@"frameOrigin"]];
        animation.delegate = self;
        [[viewToMove animator] setFrame: thisSubviewFrame];
}

...

- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag  {

    NSLog(@"ok");
}

嗨,如果你已经弄明白了,请把它作为一个答案贴出来,并把它标记为已回答。
...
for(int x=0; x<[pagesToMoveLeft count]; x++) { 

        //get a grid location
        NSRect thisSubviewFrame = NSRectFromString([subviewCoords objectAtIndex:x]);

        //get the view to move
        viewToMove = [pagesToMoveLeft objectAtIndex:x];

        CAAnimation *animation = [[viewToMove animationForKey:@"frameOrigin"] copy];
        [viewToMove setAnimations:[NSDictionary dictionaryWithObject:animation forKey:@"frameOrigin"]];
        animation.delegate = self;
        [[viewToMove animator] setFrame: thisSubviewFrame];
}

...

- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag  {

    NSLog(@"ok");
}