Question

What's the cocoa equivalent of this

[UIView animateWithDuration:2 animations:^{
    self.cell.someProperty = 12;
}];

I have tried with this, but without luck

 [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
        [context setDuration:2];
        [self.animator setSomeProperty:12.0];
    } completionHandler:^{

    }];

- (void)setSomeProperty:(CGFloat)property {
    [self.cell setSomeProperty:property];
    [self setNeedsDisplay];
}

The reason I need to animate a property, is because I have a NSCell subclass that draws it self depening on that property.

Was it helpful?

Solution

1)

Core Animation exists on MacOS and while you don't have something as well defined as "animateWithDuration" under iOS, you do have CAAnimation and CABasicAnimation.

2)

You've also discovered "NSAnimationContext" (maybe you found this closely related question? the answers in there have a really nice looking category you might be able to take advantage of).

3)

You might simply just have some typo with your setSomeProperty implementation.

OTHER TIPS

Mac OS does not have view-level animation like iOS does. The common animation framework is Core Animation. (CALayer and CAAnimation objets).

What Mac OS has is view-level classes that conform to the NSAnimatablePropertyContainer protocol. That protocol lets you ask for an animation proxy object for the object you are animating (using the animator method in the NSAnimatablePropertyContainer protocol), and then you set property values in the proxy instead of in the object, and the system animates them for you. You might want to buy either Marcus Zarra's or Bill Dudney's Core Animation books. Both of those books are rather out-of-date regarding the recent iOS additions to animation, but have a pretty comprehensive treatment of Mac OS animation.

I've only played with the Mac OS specific animation stuff, but haven't used it in real projects. (I tend to use lower-level Core Animation code on Mac OS because I'm familiar with it, and it's common with Mac. The NSAnimatablePropertyContainer protocol and the animation proxy scheme is unique to Mac OS.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top