objective-cmacoscore-animationnsviewnscolor

NSView* subClass change color animated


I am on OSX, XCode 8.3.3, Objective-C. I have subclassed NSView* to set a custom background color:

.h

@interface SHViewWhiteBackground : NSView

    @property NSColor* backgroundColor;

@end

.m

@implementation SHViewWhiteBackground

- (void)drawRect:(NSRect)dirtyRect {
    NSColor* fillColor = [NSColor whiteColor];

    if (self.backgroundColor)
        fillColor = self.backgroundColor;

    [fillColor setFill];
    NSRectFill(dirtyRect);
    [super drawRect:dirtyRect];
}

@end

Now i can call

[view setBackgroundColor:[NSColor someColor]];
[view setNeedsDisplay:YES];

to change the color. I was wondering if there is a way to animate that change?


Solution

  • I ended up using layer backed views and the pop framework for animation.