简体   繁体   中英

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?

我最终使用了层支持的视图和流行的动画框架。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM