简体   繁体   中英

CAShapeLayer problems - not drawing in nstableview

I customize a view-based tableview, and in the customize NSView, I write in the init:

NSRect testRect = imageViewRect;

CGMutablePathRef roundPath = CGPathCreateMutable();
CGPathAddArc(roundPath, NULL,
             [self arcCenter:testRect].x,
             [self arcCenter:testRect].y,
             ArcRadius,
             2 * M_PI + M_PI_2,
             M_PI_2,
             YES);

self.backgroundLayer = [CAShapeLayer layer];
self.backgroundLayer.frame = testRect;
self.backgroundLayer.path = roundPath;
self.backgroundLayer.strokeColor = [[NSColor blueColor] CGColor];
self.backgroundLayer.fillColor = nil;
self.backgroundLayer.lineWidth = 5.0f;
self.backgroundLayer.lineJoin = kCALineJoinBevel;
[self.layer addSublayer:self.backgroundLayer];
[self.backgroundLayer setFillColor:[NSColor yellowColor].CGColor];

but the layer is not shown, I really don't know where is the problem.

I wrote this in a view, and load the view in a window, the layer is showed correctly.

Have you turned your view 'self' a layer backed view? You will need to say

self.wantsLayer = true

before you can do any layer related manipulation.

Quoting documentation -

Setting the value of this property to true turns the view into a layer-backed view—that is, the view uses a CALayer object to manage its rendered content. Creating a layer-backed view implicitly causes the entire view hierarchy under that view to become layer-backed. Thus, the view and all of its subviews (including subviews of subviews) become layer-backed. The default value of this property is false.

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