0

On MacOS How to Make the NSView(backgroundColor alpha:0.3) not respond to a mouse click event。 Allow events to pass to other bottom Windows

If the full transparency default does not respond to events, if the alpha does not equal 0.0. Will prevent event delivery

I found a way to do this, but this will also ignore other mouse events! Is there any other way? Only mouse click events are penetrated

    [self.window setIgnoresMouseEvents:true];

Thanks to this friend for telling me,Override this metho

Override - (NSView *)hitTest:(NSPoint)aPoint

but if this method return nil。 it will not receive any events any more, including buttons on the view. This is not what I want

IceLuo
  • 16
  • 4
  • 1
    Does this answer your question? [Prevent an instance of NSView from receiving mouse events](https://stackoverflow.com/questions/3705106/prevent-an-instance-of-nsview-from-receiving-mouse-events) – koen Jun 29 '20 at 14:06
  • it will not receive any events any more, including buttons on the view. This is not what I want – IceLuo Jun 30 '20 at 13:27
  • Only use that for the views you don't want to accept mouse clicks, not on the whole enclosing view. – koen Jun 30 '20 at 13:29
  • I know what you're saying, but if i just want to not respond to events, your approach works。But I want to be able to pass events to other applications。I just tested it. It doesn't work that way。 It seems that the event was stopped in this window. – IceLuo Jun 30 '20 at 13:34

1 Answers1

0

I seem to have found a way,but it's not particularly good。I'm still testing

Use two Windows. Window1 window2

Add the content that needs to be handled to Windows 2. Adds content that does not need to process events to Windows 1

    [Window1 setIgnoresMouseEvents:true];
    [Window2 acceptsMouseMovedEvents:true];
    [Window1 Window2 ordered:NSWindowBelow];
    [Window1 addChildWindow:Window2 ordered:NSWindowBelow];
IceLuo
  • 16
  • 4