bryguy1300
bryguy1300

Reputation: 911

Core Animation with Blocks on the Mac?

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

Answers (3)

Caleb
Caleb

Reputation: 125037

Sometimes. NSAnimationContext and NSAnimationGroup both have completionHandler properties to which you can assign blocks, but many others don't.

Upvotes: 0

mahal tertin
mahal tertin

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

Kazuki Sakamoto
Kazuki Sakamoto

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

Related Questions