Quali sono le cause di un bordo bianco da applicare a un NSProgressIndicator visualizzato nel menu di sistema?

StackOverflow https://stackoverflow.com/questions/2714951

Domanda

Questo è ciò che accade quando creo un NSProgressIndicator e l'uso del metodo NSStatusItem -setView: per visualizzarlo nella zona barra dei menu, mentre sto eseguendo un'azione:

Esempio di incasinato NSProgressIndicator http://cl.ly/l9R/content

Quali sono le cause questa frontiera da visualizzare, e come posso rimuoverlo? Il risultato desiderato è che il controllo sia trasparente.

Ecco il codice che sto usando:

NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] init];

[progressIndicator setBezeled: NO];
[progressIndicator setStyle: NSProgressIndicatorSpinningStyle];
[progressIndicator setControlSize: NSSmallControlSize];
[progressIndicator sizeToFit];
[progressIndicator startAnimation: self];
[statusItem setView: progressIndicator]; // statusItem is an NSStatusItem instance
...
[statusItem setView: nil];
[progressIndicator stopAnimation: self];
[progressIndicator release];
È stato utile?

Soluzione

non scala il NSProgressIndicator però è anche un NSView. Creare una nuova visualizzazione che ridimensiona bene, posizione l'indicatore di stato in tale vista, e passare la vista racchiude al -[NSStatusItem setView:]. Qui è la mia realizzazione.

In NSStatusItem+AnimatedProgressIndicator.m,

- (void) startAnimation {

    NSView *progressIndicatorHolder = [[NSView alloc] init];

    NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] init];

    [progressIndicator setBezeled: NO];
    [progressIndicator setStyle: NSProgressIndicatorSpinningStyle];
    [progressIndicator setControlSize: NSSmallControlSize];
    [progressIndicator sizeToFit];
    [progressIndicator setUsesThreadedAnimation:YES];

    [progressIndicatorHolder addSubview:progressIndicator];
    [progressIndicator startAnimation:self];

    [self setView:progressIndicatorHolder];

    [progressIndicator center];

    [progressIndicator setNextResponder:progressIndicatorHolder];
    [progressIndicatorHolder setNextResponder:self];

}

- (void) stopAnimation {

    [self setView:nil];

}

- (void) mouseDown:(NSEvent *) theEvent {

    [self popUpStatusItemMenu:[self menu]];

}

- (void) rightMouseUp:(NSEvent *) theEvent {}
- (void) mouseUp:(NSEvent *) theEvent {}
…

ho aggiunto un metodo personalizzato, -[NSView center], che esegue le seguenti operazioni:

@implementation NSView (Centering)

- (void) center {

    if (![self superview]) return;

    [self setFrame:NSMakeRect(

        0.5 * ([self superview].frame.size.width - self.frame.size.width),
        0.5 * ([self superview].frame.size.height - self.frame.size.height), 

        self.frame.size.width, 
        self.frame.size.height

    )];

}

@end

Altri suggerimenti

ho visto hai risolto il problema io lascio questo è un'alternativa alla propria implementazione. È possibile utilizzare ProgressHud .

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top