Another way is to use NSView's sortSubviewsUsingFunction:context: method to re-order a collection of sibling views to your liking. For example, define your comparison function:
static NSComparisonResult myCustomViewAboveSiblingViewsComparator( NSView * view1, NSView * view2, void * context )
{
if ([view1 isKindOfClass:[MyCustomView class]])
return NSOrderedDescending;
else if ([view2 isKindOfClass:[MyCustomView class]])
return NSOrderedAscending;
return NSOrderedSame;
}
Then when you want to ensure your custom view remains above all sibling views, send this message to your custom view's superview:
[[myCustomView superview] sortSubviewsUsingFunction:myCustomViewAboveSiblingViewsComparator context:NULL];
Alternatively, you can move this code to the superview itself, and send the message sortSubviewsUsingFunction:context: to self instead.