问题
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