Pregunta

Estoy creando una mini ventana como la mini ventana iTunes:

enter image description here

Es arrastrable y tiene una imagen de fondo.

Entonces creé un NSWindowSubclase y anula su initWithContentRect:styleMask:backing:defer: método, y agregó un NSImageView lo:

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

Pero después de agregar el NSImageView Para ContentView de Window, la ventana se vuelve indgrimable.

¿Cómo hacer que la ventana se vuelva arrastrable nuevamente?

Saludos

¿Fue útil?

Solución

Crear una subclase de NSImageView y anular mouseDownCanMoveWindow método:

- (BOOL)mouseDownCanMoveWindow
{
    return YES;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top