【问题标题】:How do I programmatically setup the layer of an NSView如何以编程方式设置 NSView 的层
【发布时间】:2011-01-04 03:37:16
【问题描述】:

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

    你是不是忘了设置WantsLayer?

    contentView.wantsLayer = true
    

    这通常是问题所在!

    【讨论】:

    • 这解决了我的问题。值得注意的是,在 Swift 中,它是 contentView.wantsLayer = true
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-13
    • 2011-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多