CAShapeLayer 问题 - 无法在 nstableview 中绘制
CAShapeLayer problems - not drawing in nstableview
我自定义了一个view-based tableview,在自定义的NSView中,我在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];
但是图层没有显示出来,真不知道是哪里出了问题。
我在视图中写了这个,然后在 window 中加载视图,图层显示正确。
您是否已将视图 'self' 转换为图层支持视图?你需要说
self.wantsLayer = true
在您可以进行任何与图层相关的操作之前。
引用 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.
我自定义了一个view-based tableview,在自定义的NSView中,我在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];
但是图层没有显示出来,真不知道是哪里出了问题。
我在视图中写了这个,然后在 window 中加载视图,图层显示正确。
您是否已将视图 'self' 转换为图层支持视图?你需要说
self.wantsLayer = true
在您可以进行任何与图层相关的操作之前。
引用 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.