7

I have a window that I want users to be able to move by dragging anywhere in the window content (not just the titlebar). I know that this can be done via the NSWindow movableByWindowBackground method, however this doesn't appear to work by itself.

I gather that overriding NSView mouseDownCanMoveWindow may be necessary. But I can't easily do that for all parent views (split views, etc). Making it a textured window didn't help. Unsurprisingly, subclassing NSWindow to override isMovableByWindowBackground didn't help either.

Is it really necessary to subclass all parent views in the window to make this work?

Community
  • 1
  • 1
Dejal
  • 813
  • 6
  • 18

2 Answers2

6

On OS X 10.11, setting the NSWindow's property movableByWindowBackground to YES works.

There is no longer any need to subclass for this behaviour.

Graham Miln
  • 2,724
  • 3
  • 33
  • 33
  • 1
    In my experience, that's not the case. I have an NSSplitView that covers a window and I've set that property. The window is not draggable from background areas. I'm building against 10.11 and my deployment target is 10.11+ – Bryan Mar 25 '16 at 07:20
  • @Bryan consider logging a bug with Apple against `NSSplitView`; it sounds like unhandled mouse events are not being passed up through the `NSResponder` chain as expected. – Graham Miln Mar 25 '16 at 09:16
  • 1
    I would say that's correct. I overrode -mouseDownCanMoveWindow in the splitView, returned YES, and that solved the problem. – Bryan Mar 26 '16 at 18:03
1

In NSSplitView you add:

override var mouseDownCanMoveWindow: Bool {
    return true
}
BackSpace
  • 119
  • 1
  • 4