Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animations for NSView

I have been making apps for iOS and have started making ones for Mac OS X lately. I am trying to do some animations on NSView.

What I want to do is bounce the scale an NSView so it shrinks to 70% and then back to 100% with a bounce. Now I can do the scale/sizing parts, but it's the animation bit I can't now do.

With iOS I would have used the following on UIView:

+ (void)animateWithDuration:(NSTimeInterval)duration
                 animations:(void (^)(void))animations
                 completion:(void (^)(BOOL finished))completion

Using this it means when the previous animation finishes I can start the new one. I've been looking for a similar functions for Mac OS X. I've found the following:

[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:2.0];
// Set end state of objects to animate
[NSAnimationContext endGrouping];

This is similar to the way I used to animate objects before iOS 4. But then animation blocks (like show at the top) were introduced and I've been using them ever since. So my question is, are there animation blocks for Mac OS X that I've missed? Or is there another way of doing it?

like image 447
Baza207 Avatar asked Mar 05 '26 08:03

Baza207


1 Answers

If you are using Mac OS X 10.7 you probably will find it more natural to use the blocks-based NSAnimationContext API:

+ (void)runAnimationGroup:(void (^)(NSAnimationContext *context))changes
        completionHandler:(void (^)(void))completionHandler
like image 173
torrey.lyons Avatar answered Mar 08 '26 20:03

torrey.lyons



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!