我创建 NSViewController。它管理我的视图层次结构并在一个 NSBox 中设置其他视图。
- (void)displayViewController:(ManagingViewController *)vc
{
NSWindow *w = [box window];
NSView *v = [vc view];
[box setContentView:v];
}
我有两种不同的观点。这些视图具有 Quartz Composer 根层和 CALayer 子层。
// ----------
// Root Layer
// ----------
QCCompositionLayer* rootLayer = [QCCompositionLayer compositionLayerWithFile:[[NSBundle mainBundle]
pathForResource:@"BackgroundHome"
ofType:@"qtz"]];
[self setLayer:rootLayer];
[self setWantsLayer:YES];
// ----------
// Menu Layer
// ----------
menusLayer = [CALayer layer];
menusLayer.frame = rootLayer.bounds;
menusLayer.layoutManager =[CAConstraintLayoutManager layoutManager];
[rootLayer addSublayer:menusLayer];
// --------------
// Menu Items
// --------------
NSInteger i;
for (i=0;i<[section count];i++) {
NSString *name = [section objectAtIndex:i];
CATextLayer *menuItemLayer = [CATextLayer layer];
menuItemLayer.string = name;
menuItemLayer.font = @"Lucida-Grande";
menuItemLayer.fontSize = fontSize;
menuItemLayer.foregroundColor = CGColorCreateGenericRGB(1.0,1.0,1.0,1.0);
[menuItemLayer addConstraint:[CAConstraint
constraintWithAttribute:kCAConstraintMaxY
relativeTo:@"superlayer"
attribute:kCAConstraintMaxY
offset:-(i*height+spacing+initialOffset)]];
[menuItemLayer addConstraint:[CAConstraint constraintWithAttribute:kCAConstraintMidX
relativeTo:@"superlayer"
attribute:kCAConstraintMidX]];
[menusLayer addSublayer:menuItemLayer];
}
[menusLayer layoutIfNeeded];
我运行我的应用程序,我可以替换视图,但我只查看 QCCompositionLayer。当我直接使用我的自定义 NSView 类时,没有 NSView 层次结构,我可以查看所有内容。错误在哪里?
原谅我的英语不好,谢谢