CALayer + NSOutlineView/NSTableView

梦想与她 提交于 2019-12-08 02:25:49

问题


Here is the issue: a view-based NSOutlineView (or NSTableView, both have the issue) contains a custom control hosting a CALayer, for custom animation purposes. When resizing the outline view, or after deleting rows (animated deletion), the CALayer draws at the wrong place.

This is just after an horizontal resize (the gray square is the CALayer):

This is just after deleting the row where the gray square is missing (the gray square is the CALayer):

It looks like the CALayer is drawn a little later than the view hierarchy itself, and in the case of the row deletion, isn't redrawn/removed at all. Here is a little video: http://cl.ly/image/2E2X1Y3W2s3O

The code is basically:

// MyButton.m

- (id)initWithFrame:(NSRect)frame
{
    /...
        [self setLayer:[[MyCALayer alloc] init]];
        [self setWantsLayer:YES];
        [self.layer setDelegate:self];

        [self setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawOnSetNeedsDisplay];
        [self setLayerContentsPlacement:NSViewLayerContentsPlacementCenter];
    }
    return self;
}

- (void)viewDidChangeBackingProperties
{
    [super viewDidChangeBackingProperties];
    [[self layer] setContentsScale:[[self window] backingScaleFactor]];
}

// MyCALayer.m

- (id)init  // ...
- (id)initWithLayer:(id)layer // ...

- (void)drawInContext:(CGContextRef)context
{
    // draw a simple rect
}

+ (BOOL)needsDisplayForKey:(NSString *)key
{
    return [key isEqualToString:@"myProgressKey"];
}

Am I missing anything? Or have you already had this kind of bug with NSOutlineView/NSTableView?

Thanks a lot!

来源:https://stackoverflow.com/questions/25851910/calayer-nsoutlineview-nstableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!