我正在用下面的代码动画一个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"]];}
有人能帮我吗?
谢谢!
发布于 2012-08-29 10:16:43
您可以使用此函数:
[[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-17 12:21:15
[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"];
}https://stackoverflow.com/questions/12005097
复制相似问题