How to drag NSWindow with NSImageView into its contentView?

I create a mini window like an iTunes mini window:

enter image description here

It is dragged and has a background image on it.

Then I subclassed NSWindow and overrides its initWithContentRect:styleMask:backing:defer: and added NSImageView to it:

 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag { contentRect.size = CGSizeMake(287, 287); self = [super initWithContentRect:contentRect styleMask:aStyle backing:bufferingType defer:flag]; if (self) { [self setMovableByWindowBackground:YES]; [self setOpaque:NO]; [self setBackgroundColor:[NSColor colorWithCalibratedWhite:1.0 alpha:0.5]]; NSImageView *imageView = [[NSImageView alloc] initWithFrame:(CGRect){CGPointZero, contentRect.size}]; imageView.image = [NSImage imageNamed:@"MiniWindow.png"]; [self.contentView addSubview:imageView]; } return self; } 

But after I add NSImageView to the window contentView, the window will become inaccessible.

How to make the window draggable again?

Best wishes

+8
cocoa macos nswindow
source share
1 answer

Subclass the NSImageView method and override mouseDownCanMoveWindow :

 - (BOOL)mouseDownCanMoveWindow { return YES; } 
+10
source share

All Articles