0
votes

How do I disable all mouse events to a specific NSView(and all its subviews)

For eg: In following image, I have a scrollView and a border view(say MyBorderView) over it
The functionality I want to acheive is to disable all mouse events to scroll view when button is pressed.

My fix to it is to override mouseDown and rightMouseDown event of NSView. This seems to work fine but fails for scroll.

In simple words, I want to achieve some thing like [_scrollView disableAllMouseEvents]

enter image description here

1

1 Answers

0
votes

Override the method:

- (void)scrollWheel:(NSEvent *)theEvent;

For example, you have a boolean variable disableEvents for enable or disable events in your scroll view. The code will be:

- (void)scrollWheel:(NSEvent *)theEvent
{
    // No disable events ---> disableEvents = NO
    if (!disableEvents) {
        [super scrollWheel:theEvent];
    }
}

If you set disableEvents = YES the scroll will be disabled. On the other hand, you need disable the scrollers too or the scroll works moving them:

[self setHorizontalScroller:nil];
[self setVerticalScroller:nil];

If you need reverse the scrollers later, just write:

NSScroller *scrollerHorizontal = [[NSScroller alloc]init];
NSScroller *scrollerVertical = [[NSScroller alloc]init];

[self setHorizontalScroller:scrollerHorizontal];
[self setVerticalScroller:scrollerVertical];

Good luck!