Reputation: 50727
I have a transparent .png
image that lays over an NSView
and it should look like this:
However, sometimes, with no rhyme or reason or indication that it is going to do this, the NSImageView
falls behind the NSView
:
I am not sure how to keep the NSImageView
above the NSView
, or why it even falls behind the NSView
.
Here is what it looks like in Interface Builder:
I have tried the following with same results:
[header removeFromSuperview];
[mainView addSubview:header positioned:NSWindowAbove relativeTo:nil];
What is a better way to achieve this effect?
Upvotes: 1
Views: 1154
Reputation: 50727
Turns out that I had to re-arrange some of the views in Interface Builder, then in code:
[[header layer] setZPosition:1.0f];
Upvotes: 2
Reputation: 25281
When you have two overlapping NSView on the same level it is undefined what the drawing order will be. You can sort the drawing of the subviews using SubviewsUsingFunction:context:
. You'll have to provide a comparison function that compares based on some value (e.g. tag):
NSComparisonResult viewCompareByTag(NSView *firstView, NSView *secondView, void *context) {
return ([firstView tag] > [secondView tag]) ? NSOrderedAscending : NSOrderedDescending;
}
[mySuperView sortSubviewsUsingFunction:&viewCompareByTag context:nil];
Upvotes: 2
Reputation: 3991
Cocoa UI elements that overlap have an undefined drawing order, and Apple states that you shouldn't overlap them. You could create some custom drawing code to make your current design work. However, honestly I would change the design so it matches with Mac OS X's human interface guidelines. You can read about these at the link below. http://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/AppleHIGuidelines/XHIGIntro/XHIGIntro.html%23//apple_ref/doc/uid/TP30000894-TP6
Upvotes: 2