Baza207
Baza207

Reputation: 2142

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?

Upvotes: 2

Views: 6307

Answers (1)

torrey.lyons
torrey.lyons

Reputation: 5589

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

Upvotes: 14

Related Questions