NSImageView与CALayer在上面

问题描述 投票:0回答:1

这里的目标是在用户看到的NSImageView的“顶部”选择层。但是,我的选择层不知何故以“后退”结束。这是我从NSImageView子类重写的-setImage:

-(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不起作用。

macos cocoa core-animation calayer nsview
1个回答
0
投票

感谢mohacs,他/她在this comment回答了这个问题 -

您可以尝试更改图层的z顺序。 http://stackoverflow.com/questions/25371109/z-index-of-image-and-separator-in-uitableviewcell/25372394#25372394 - mohacs 2014年8月30日21:04

© www.soinside.com 2019 - 2024. All rights reserved.