I'm creating a mini window like the iTunes mini window:
It's draggable and have a background image on it.
Then I created a NSWindow
's subclass and overrides its initWithContentRect:styleMask:backing:defer:
method, and added an 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 the NSImageView
to window's contentView, the window become undraggable.
How to make the window become draggable again?
Best regards
Create an subclass of NSImageView
and override mouseDownCanMoveWindow
method:
- (BOOL)mouseDownCanMoveWindow
{
return YES;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With