我正在创建一个像iTunes mini窗口一样的迷你窗口:
它是可拖动的,并有一个背景图像.
然后我创建了一个NSWindow的子类并覆盖了它的initWithContentRect:styleMask:backing:defer:方法,并为其添加了一个NSImageView:
- (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; }
但是在我将NSImageView添加到窗口的contentView之后,窗口变得不可分割.
如何使窗口再次变得可拖动?
最好的祝福
解决方法
创建NSImageView的子类并覆盖mouseDownCanMoveWindow方法:
- (BOOL)mouseDownCanMoveWindow { return YES; }