Reputation: 911
Is it possible to perform animations with Core Animation using blocks on the Mac similarly to how one can do it on iOS? I'd like to be able to set up completion blocks at the end of an animation to remove views, etc. I know that this can be achieved with delegates, but obviously the whole point of blocks with animations is to avoid that pain.
Upvotes: 0
Views: 627
Reputation: 125037
Sometimes. NSAnimationContext and NSAnimationGroup both have completionHandler
properties to which you can assign blocks, but many others don't.
Upvotes: 0
Reputation: 3414
CATransaction + (void)setCompletionBlock:(void (^)(void))block
The block object called when animations for this transaction group are completed.
[CATransaction begin];
[CATransaction setAnimationDuration:5.0];
[CATransaction setCompletionBlock:^{
// this will be done when animation has completed
}];
//do some things to your layers
[CATransaction commit];
Upvotes: 3
Reputation: 14009
Twitter is offering TwUI that uses Core Animation with Blocks. It might help you.
https://github.com/twitter/twui
https://github.com/twitter/twui/blob/master/lib/UIKit/TUIView+Animation.m
@interface TUIViewAnimation : NSObject <CAAction>
{
/* snip */
void (^animationCompletionBlock)(BOOL finished);
Upvotes: 1