objective-c – 如何在Mac上与图层支持的视图进行交互
我正在设计一个包含多个标签和文本字段的用户界面.我想像这样设置UI:
>为我的NSWindow的内容视图设置背景图案 我通过使内容视图成为层支持的视图解决了第一个问题,如Apple’s documentation of
然后从绘制我的CGImage的CGPattern生成CGColorRef: NSView *mainView = [[self window]contentView]; [mainView setWantsLayer:YES]; 要将背景图像设置为模式,我在这里使用了How to tile the contents of a CALayer的答案,以完成第一项任务. 但是对于第二个任务,添加图标我使用下面的代码: CGImageRef iconImage = NULL; NSString *path = [[NSBundle mainBundle] pathForResource:@"icon_128" ofType:@"png"]; if(path != nil) { NSURL *imageURL = [NSURL fileURLWithPath:path]; provider = CGDataProviderCreateWithURL((CFURLRef)imageURL); iconImage = CGImageCreateWithPNGDataProvider(provider,NULL,FALSE,kCGRenderingIntentDefault); CFRelease(provider); } CALayer *iconLayer = [[CALayer alloc] init]; // layer is the mainView's layer CGRect layerFrame = layer.frame; CGFloat iconWidth = 128.f; iconLayer.frame = CGRectMake(0.f,CGRectGetHeight(layerFrame)-iconWidth,128.f,128.f); iconLayer.contents = (id)iconImage; CGImageRelease(iconImage); [layer insertSublayer:iconLayer atIndex:0]; [iconLayer release]; 问题 >我不确定我是否违反Apple对图层支持视图的限制,您不应该直接与图层进行交互.设置图层的背景颜色时,我正在与图层直接交互,或者我在这里弄错了? 关于如何使用CoreAnimation和标准控件分割设计用户界面的任何建议都值得赞赏. 请注意,我在这里谈论的是Mac. 解决方法
没有层支持需要恕我直言:
为1.我做一个模式图像 NSImage *patternImage = [NSImage imageNamed:@"pattern"]; [window setBackgroungdColor:[NSColor colorWithPatternImage:patternImage]]; for 2.添加NSImageView作为contentview的子视图 NSImageView *v = ... [[window contentView] addSubview:v]; 在mac上一些视图不能很好地响应IF层支持::例如pdfview (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |