带有图层的NSView在所有内容上绘制 [英] NSView with layer is drawn over all content

查看:150
本文介绍了带有图层的NSView在所有内容上绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSView,我改变一些属性,使它成为一个圆角矩形,灰色的颜色,并添加到我的视图(一切后面)

I have an NSView, which I change some properties to give make it a rounded rectangle, with a gray color, and add it to my view (behind everything)

float gray = 60.0f/255.0f;
NSView* background = [[NSView alloc] initWithFrame: self.iconContainer.frame];
CALayer *viewLayer = [CALayer layer];
[viewLayer setBackgroundColor:CGColorCreateGenericRGB(gray, gray,gray, 1)]; //RGB plus Alpha Channel
[viewLayer setCornerRadius:5.0f];
[background setWantsLayer:YES]; // view's backing store is using a Core Animation Layer
[background setLayer:viewLayer];  

// Place view behind all other views
[self.iconContainer addSubview:background positioned:NSWindowBelow relativeTo:nil];

然而,无论我尝试什么, b $ b

However no matter what I try, that particular view is drawn above everything else.

推荐答案

通常,这种行为是由在子视图上使用Core Animation层引起的,而超级视图没有任何内容。

Usually, this behaviour is caused by the use of Core Animation layers on a subview, while the superview hasn't any.

在superview上启用Core Animation图层应该可以解决这个问题,因为任何子视图都将使用Cora动画层来绘制,使绘图过程遵循子视图的顺序。

Enabling Core Animation layers on the superview should fix the issue, as any subviews will then be drawn using Cora Animation layers, making the drawing process respect the order of subviews.

这篇关于带有图层的NSView在所有内容上绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆