如何以编程方式设置NSView层

时间:2011-01-04 03:37:17

标签: cocoa calayer

这样做的正确方法是什么?这是我正在尝试的。但是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的子类。

1 个答案:

答案 0 :(得分:9)

你有没有忘记setWantsLayer?

contentView.wantsLayer = true

这通常是问题!