0

我正在使用这段代码为 NSScrollView 滚动制作动画:

    [NSAnimationContext beginGrouping];
    NSClipView* clipView = [self contentView];
    NSPoint newOrigin = [clipView bounds].origin;
    newOrigin.x = page*kGalleryWidth;
    [[clipView animator] setBoundsOrigin:newOrigin];
    [NSAnimationContext endGrouping];

现在我正在尝试获取触发动画结束的事件。我已经阅读了几行代码,使用 CAAnimation,我很容易实现它,但我做不到。

我已经尝试了以下代码:

CAAnimation *moveAnimation = [[self.contentView animationForKey:@"frameOrigin"] copy];
moveAnimation.delegate = self;
[self.contentView setAnimations:[NSDictionary dictionaryWithObject:moveAnimation forKey:@"frameOrigin"]];
  • (void)animationDidStop:(CAAnimation *)动画完成:(BOOL)flag{

    NSLog(@"停止!");

}

有人可以帮助我吗?

谢谢!

4

2 回答 2

0
[UIView beginAnimations:@"goback" context:nil];
[UIView setAnimationDuration:0.3f];
[UIView setAnimationBeginsFromCurrentState:NO];
dragOperation.draggable.center =dragOperation.initialPoint;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector: @selector(animationDidStop:finished:context:)];
UIView commitAnimations];




-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    [self.layer removeAnimationForKey:@"goback"];
}
于 2012-08-17T12:21:15.417 回答
0

您可以使用此功能:

[[NSAnimationContext currentContext] setCompletionHandler:<#(void (^)(void))completionHandler#>]

 [NSAnimationContext beginGrouping];
    [[NSAnimationContext currentContext] setCompletionHandler:^{
        NSLog(@"animation stop!");
    }];
    NSClipView* clipView = [self contentView];
    NSPoint newOrigin = [clipView bounds].origin;
    newOrigin.x = page*kGalleryWidth;
    [[clipView animator] setBoundsOrigin:newOrigin];
    [NSAnimationContext endGrouping];
于 2012-08-29T10:16:43.330 回答