5
votes

I'm struggling to understand why mouseDragged is getting called for one of my NSView subclasses but not for the other when the mouse is positioned outside the view.

Subclass 1 is programatically added to an NSWindow, which is then added as a child window to the main app window. When the mouse is clicked inside the view and dragged, mouseDragged continues to get called even when the mouse goes outside the view's frame. This is what I want to happen.

Subclass 2 is assigned in the XIB file to a custom view object in the main window of the app. In this case, the mouseDragged event only fires when the mouse remains inside the view.

Anything obvious I'm missing?

1
Can we see a little more? Maybe your view subclasses or something - because that doesn't look like expected behavior.Vervious
I am seeing something similar, but it is the same NSView subclass in each window. One (in the parent window) works as expected. The other (in a child window) sees the mouseDragged only while the mouse is over the view. I would be very curious to know how the system keeps track of the mouseDown view to know which view to send the mouseDragged to.Peter N Lewis

1 Answers

0
votes

I experienced something similar, but it is the same NSView subclass in each window. One (in the parent window) works as expected. The other (in a child window) sees the mouseDragged only while the mouse is over the view.

It turned out the cause was having an NSImageView in the same view as the problematic view, but overlapping it. Because the NSImageView only drew the image in part of its bounds, this had never been a problem, but it turns out this was the cause of the issue with the problematic view tracking.

I adjusted the way the NSImageView was added to place it at the bottom of the subviews:

[parentView addSubview:myImageView positioned:NSWindowBelow relativeTo:nil];

The problematic view was also in parentView already, so addSubview: was adding myImageView above the problematic view.

This resolved the issue for me.