Pergunta

Estou criando uma mini janela como a mini janela do iTunes:

enter image description here

É arrastável e tem uma imagem de fundo.

Então eu criei um NSWindowSubclasse e substitui seu initWithContentRect:styleMask:backing:defer: método e adicionou um NSImageView para isso:

- (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;
}

Mas depois de adicionar o NSImageView Para o Window ContentView, a janela se torna imperturbável.

Como fazer a janela se tornar arrastável novamente?

Atenciosamente

Foi útil?

Solução

Criar uma subclasse de NSImageView e substituir mouseDownCanMoveWindow método:

- (BOOL)mouseDownCanMoveWindow
{
    return YES;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top