如何以编程方式设置NSView层

问题描述 投票:4回答:1

这样做的正确方法是什么?这是我正在尝试的。但是dotLayer上从不调用display:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    DotLayer *dotLayer = [[DotLayer alloc]init ];
    dotLayer.frame= CGRectMake(10, 10, 100, 100);
    dotLayer.nDots = 4;
    NSView *contentView = window.contentView;
    CALayer *layer = [[CALayer alloc]init];
    layer.frame = CGRectMake(0,0,200,200);
    contentView.layer = layer;
    [layer addSublayer:dotLayer];
    [dotLayer setNeedsDisplay];
}

DotLayer是CALayer的子类。

cocoa calayer
1个回答
9
投票

你有没有忘记setWantsLayer?

contentView.wantsLayer = true

这通常是个问题!

© www.soinside.com 2019 - 2024. All rights reserved.