可可:在OSX上的动画后运行块 [英] Cocoa: run block after animation on OSX

查看:112
本文介绍了可可:在OSX上的动画后运行块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用animator实现动画,例如

  [[self.view animator] setFrame:newFrame]; 

但我想在动画完成后运行方法或块,如下:

  [[self.view animator] setFrame:newFrame onComplete:^ {
NSLog(@****);
}];有没有什么方法来实现它?



< h2_lin>解决方案

你应该使用 NSAnimationContext ,它的 completionHandler

  [NSAnimationContext beginGrouping]; 
[[NSAnimationContext currentContext] setCompletionHandler:^ {
NSLog(@****);
}];
[[self.view animator] setFrame:newFrame];
[NSAnimationContext endGrouping];


I'm using animator to implement an animation, like

[[self.view animator] setFrame:newFrame];

but I want to run a method or block after the animation finish, as follow:

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

Is there any way to implement it?

解决方案

You should use NSAnimationContext and it's completionHandler:

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

这篇关于可可:在OSX上的动画后运行块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆