Nightowl
Nightowl

Reputation: 55

How to drag an image view within a window using swift (OS X not IOS)

I am creating a Mac application but having difficulty when dragging a window with an image on the view. Basically I can drag the main window but unable to drag the window when clicking and dragging the image view.

I can enable dragging on the main window with "window.movableByWindowBackground = true" seems to work but unable to get this working when dragging the image view on the window.

enter image description here

Any help would be greatly appreciated.

Upvotes: 1

Views: 1417

Answers (1)

Eric Aya
Eric Aya

Reputation: 70096

The trick is to subclass your NSImageView and override the mouseDownCanMoveWindow property:

class MyImageView: NSImageView {

    override var mouseDownCanMoveWindow:Bool {
        return true
    }

}

Upvotes: 1

Related Questions