I need to draw a transparent overlay over another NSView, specifically, a WebView. The goal is to display some notification text with a semi-transparent background. For my first experiment I created an Overlay view that just displays a green square:
class Overlay: NSView {
override func drawRect(dirtyRect: NSRect) {
NSColor.greenColor().setFill()
NSBezierPath(rect: CGRect(x: 10, y: 10, width: 1000, height: 1000)).fill()
}
}
and then, in my code, I instantiate them and add them like this:
webView = WebView(frame: bounds)
overlay = Overlay(frame: bounds)
addSubview(webView)
addSubview(overlay)
To my surprise, that only works with some pages. For example, if you go to https://twitter.com/screensavrninja, it grayes out the whole page and shows you a sign out pop-in. Both the graying out and the pop-in happen on top of the green square.
Why is that happening? What's the appropriate way to have an overlay and have it remain on top?