我无法使用图层托管视图。如预期(视图充满黑色)提供该版本的initWithFrame:
作品“想要的Core Animation层”在Interface Builder中选择:无法显示图层托管视图
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
[self setWantsLayer:YES];
[[self layer] setBackgroundColor:CGColorGetConstantColor(kCGColorBlack)];
[[self layer] setContents:[NSImage imageNamed:NSImageNameBonjour]];
}
return self;
}
我希望能够以编程方式配置的看法,所以我想删除依赖于Interface Builder。以下是旨在实现这一目标的第二个版本。这不起作用。的观点保持不变颜色与父视图:
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
CALayer *rootLayer = [CALayer layer]; //Added this line,
[self setLayer:rootLayer]; //and this line only
[self setWantsLayer:YES];
[[self layer] setBackgroundColor:CGColorGetConstantColor(kCGColorBlack)];
[[self layer] setContents:[NSImage imageNamed:NSImageNameBonjour]];
}
return self;
}
我从文档中复制的代码和搜索,我发现网页和所有的例子确实做到了这一点,但它不工作!
我在做什么错?