Drag a window by clicking on image view

The window I’m using has an image view that takes up the entire view and when u click the image to try and drag the window you cant. How would you allow the image view to let the window drag when u click the image?

Have you tried setting Refuses First Responder in IB?

How do you do that, that isn’t one of the options in the attributes inspector.

It is here – under State, just below Enabled and Continuous.

Ok, but those options are not available for an NSImageview

I think you need to override the default method mouseDownCanMoveWindow, which has to be done in an Objective-C file. I was able to do it like this in a project named Drag:

Add a new file of the Objective-C class and make the files look like this:

//  C_Drag.h
//  Drag

#import <Cocoa/Cocoa.h>

@interface C_Drag : NSImageView {

//  C_Drag.m
//  Drag

#import "C_Drag.h"

@implementation C_Drag

-(BOOL)mouseDownCanMoveWindow {
    return YES;

The only thing I did in the .h file was to change the superclass of my class to NSImageView. In the .m file I put in the new implementation of the mouseDownCanMoveWindow method that overrides the NSImageView class method which returns NO.

In the nib, I dragged an Image Well into my window and changed its class to C_Drag (the name of my Obj-C file). My applescript looks like this (notice its parent property is set to C_Drag):

script DragAppDelegate
	property parent : class "C_Drag"
	property NSImage : class "NSImage"
	property myWindow : missing value
	property myView : missing value
	on applicationWillFinishLaunching_(aNotification)
		myWindow's setMovableByWindowBackground_(1)
		myView's setImage_(NSImage's imageNamed_("s11.tiff"))
		myView's setImageScaling_(1)
	end applicationWillFinishLaunching_
end script

The setMovableByWindowBackground_ method makes the window draggable anywhere inside it, but not over an image view unless you do the override like we did above.

You can also override mouseDownCanMoveWindow in AS, by subclassing NSImageView. Just make a new AS class, make it’s parent NSImageView instead of NSObject, add the handler, and then change the class of the image view to the new class.