NSImageView with CALayer on top
问题描述:
这里的目标是在用户看到NSImageView的顶部有一个选择图层。但是,我的选择层总是以某种方式结束于“后退”。这是我从我的NSImageView子类重写-setImage:NSImageView with CALayer on top
-(void)setImage:(NSImage *)newImage {
if(newImage) {
// compute image location in view
_imageLocation.x = ([self frame].size.width - [newImage size].width)/2.0;
_imageLocation.y = ([self frame].size.height - [newImage size].height)/2.0;
// call to parent
[super setImage:newImage];
if(_pixelDataManager) {
_pixelDataManager = nil;
}
_pixelDataManager = [[PixelDataManager alloc] initWithImageForData:newImage];
_selectionLayer = [CALayer layer];
[_selectionLayer setBorderColor:[[NSColor yellowColor] CGColor]];
[_selectionLayer setBorderWidth:2.0];
[_selectionLayer setCornerRadius:0.0];
[[self layer] addSublayer:_selectionLayer];
}
else {
[super setImage:nil];
_pixelDataManager = nil;
_imageLocation.x = 0.0;
_imageLocation.y = 0.0;
}
}
这里的重点是黄色盒子。我有一个不同的项目中的自定义NSView类似的代码,这似乎是好的,但不明白为什么这不适用于NSImageView。
答
感谢mohacs,他/她回答了这个问题。
您可以尝试更改图层的z顺序。 http://stackoverflow.com/questions/25371109/z-index-of-image-and-separator-in-uitableviewcell/25372394#25372394 – mohacs 2014-08-30 21:04:58
@mohacs,感谢您先生/女士这工作! – xBACP 2014-08-30 21:27:12
不客气。 – mohacs 2014-08-30 22:46:51