Cocoa:OSX上的动画后运行块

NOr*_*der 6 macos cocoa

我正在使用动画师来实现动画,比如

[[self.view animator] setFrame:newFrame];
Run Code Online (Sandbox Code Playgroud)

但是我希望在动画完成后运行一个方法或块,如下所示:

[[self.view animator] setFrame:newFrame onComplete:^{
    NSLog(@"****");
}];
Run Code Online (Sandbox Code Playgroud)

有没有办法实现它?

Dmi*_*try 13

你应该使用NSAnimationContext它是completionHandler:

[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setCompletionHandler:^{
    NSLog(@"****");
}];
[[self.view animator] setFrame:newFrame];
[NSAnimationContext endGrouping];
Run Code Online (Sandbox Code Playgroud)

  • 我认为你应该在执行动画之前设置完成处理程序. (3认同)