Search code examples
objective-cmacoscocoacore-animation

UIView animateWithDuration equivalent for OSX Cocoa


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.


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.