Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move window by dragging background (movableByWindowBackground)

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?

like image 629
Dejal Avatar asked Jan 23 '15 05:01

Dejal


2 Answers

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.

like image 110
Graham Miln Avatar answered Oct 01 '22 15:10

Graham Miln


In NSSplitView you add:

override var mouseDownCanMoveWindow: Bool {
    return true
}
like image 27
BackSpace Avatar answered Oct 01 '22 17:10

BackSpace