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];
I find another solution from WWDC video and hope the bellow code helps someone else
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With