The problem
I have a transparent NSView
on a transparent NSWindow
. The view's drawRect:
method draws some content (NSImage
s, NSBezierPath
s and NSString
s) on the view but leaves parts of it transparent.
Clicking on the regions of the view that have been drawn on invokes the usual mouse event handling methods (mouseDown:
and mouseUp:
).
Clicking on the transparent areas gives focus to whatever window is behind my transparent window.
I would like to make parts of the transparent region clickable so that accidentally clicking between the elements drawn on my view does not cause the window to lose focus.
Solutions already attempted
- Overriding the
NSView
'shitTest:
method. Found thathitTest:
was only called when clicking on a non-transparent area of the view. - Overriding the
NSView
'sopaqueAncestor
method. Found that this was not called when clicking on any part of the view. - Filling portions of the transparent area with
[NSColor clearColor]
in thedrawRect:
method, and with an almost-but-not-quite-transparent colour. This had no effect. - Experimented with the
NSTrackingArea
class. This appears to only add support formouseEntered:
,mouseExited:
,mouseMoved:
, andcursorUpdate:
methods, notmouseUp:
andmouseDown:
.