1dayitwillmake
1dayitwillmake

Reputation: 2339

NSView with layer is drawn over all content

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];

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

Upvotes: 3

Views: 1285

Answers (1)

Macmade
Macmade

Reputation: 54020

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

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.

Upvotes: 7

Related Questions