macos – 如何在其contentView上使用NSImageView拖动NSWindow?

我正在创建一个像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;
}

相关文章

我正在用TitaniumDeveloper编写一个应用程序,它允许我使用Ja...
我的问题是当我尝试从UIWebView中调用我的AngularJS应用程序...
我想获取在我的Mac上运行的所有前台应用程序的应用程序图标....
我是一名PHP开发人员,我使用MVC模式和面向对象的代码.我真的...
OSX中的SetTimer在Windows中是否有任何等效功能?我正在使用...
我不确定引擎盖下到底发生了什么,但这是我的设置,示例代码和...