I have a transparent NSView
on a transparent NSWindow
. The view\'s drawRect:
method draws some content (NSIma
You can override the hitTest
method in your NSView
so that it always returns itself.
According to the NSView documentation, the hitTest
method will either return the NSView that the user has clicked on, or nil
if the point is not inside the NSView
. In this case, I would invoke [super hitTest:]
, and then return the current view only if the result would otherwise be nil
(just in case your custom view contains subviews).
- (NSView *)hitTest:(NSPoint)aPoint
{
NSView * clickedView = [super hitTest:aPoint];
if (clickedView == nil)
{
clickedView = self;
}
return clickedView;
}
As far as I know, click events to transparent portions of windows aren't delivered to your application at all, so none of the normal event-chain overrides (i.e -hitTest:, -sendEvent:, etc) will work. The only way I can think of off the top of my head is to use Quartz Event Taps to capture all mouse clicks and then figure out if they're over a transparent area of your window manually. That, frankly, sounds like a huge PITA for not much gain.
I had the same problem. It looks like [window setIgnoresMouseEvents:NO]
will do it.
(On Lion, at least. See http://www.cocoabuilder.com/archive/cocoa/306910-lion-breaks-the-ability-to-click-through-transparent-window-areas-when-the-window-is-resizable.html)
You can use an event monitor to catch events outside a window/view. https://developer.apple.com/library/mac/documentation/cocoa/conceptual/eventoverview/MonitoringEvents/MonitoringEvents.html
Did you try overriding
- (NSView *)hitTest:(NSPoint)aPoint
in your NSView sublcass?
George : you mentioned that you tried filling portions with an almost but not quite transparent color. In my testing, it only seems to work if the alpha value is above 0.05, so you might have some luck with something like this:
[[NSColor colorWithCalibratedRed:0.01 green:0.01 blue:0.01 alpha:0.05] set];
It's an ugly kludge, but it might work well enough to avoid using an event tap.