我创建了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层次结构时,我可以看到所有。哪里出错?
请原谅我糟糕的英语,谢谢