这样做的正确方法是什么?这是我正在尝试的。但是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的子类。
答案 0 :(得分:9)
你有没有忘记setWantsLayer?
contentView.wantsLayer = true
这通常是问题!