Domanda

Sto creando una mini finestra come la mini finestra di iTunes:

enter image description here

È trascinabile e avere un'immagine di sfondo su di esso.

Poi ho creato un NSWindowSottoclasse e prevale in initWithContentRect:styleMask:backing:defer: metodo e aggiunto un NSImageView A esso:

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

Ma dopo aver aggiunto il NSImageView Per la visione di ContentView di Window, la finestra diventa inarrestabile.

Come far diventare di nuovo trascinabile la finestra?

Distinti saluti

È stato utile?

Soluzione

Crea una sottoclasse di NSImageView e sovrascrivere mouseDownCanMoveWindow metodo:

- (BOOL)mouseDownCanMoveWindow
{
    return YES;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top