Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa: run block after animation on OSX

Tags:

macos

cocoa

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?

like image 992
NOrder Avatar asked Sep 03 '12 00:09

NOrder


2 Answers

You should use NSAnimationContext and it's completionHandler:

[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setCompletionHandler:^{
    NSLog(@"****");
}];
[[self.view animator] setFrame:newFrame];
[NSAnimationContext endGrouping];
like image 162
Dmitry Avatar answered Sep 20 '22 22:09

Dmitry


I find another solution from WWDC video and hope the bellow code helps someone else

enter image description here

like image 26
NOrder Avatar answered Sep 22 '22 22:09

NOrder