Quelles sont les causes d'une bordure blanche à appliquer à un NSProgressIndicator affiché dans le menu du système?

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

Question

Ce qui se passe quand je crée un NSProgressIndicator et utiliser la méthode de NSStatusItem de -setView: pour l'afficher dans la zone de la barre de menus alors que je joue une action:

Exemple de sali NSProgressIndicator http://cl.ly/l9R/content

Quelles sont les causes de cette frontière à afficher, et comment puis-je le supprimer? Le résultat recherché est que le contrôle soit transparent.

Voici le code que je utilise:

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];
Était-ce utile?

La solution

Ne pas l'échelle NSProgressIndicator si elle est aussi une NSView. Créer une nouvelle vue qui redimensionne bien, la position de l'indicateur d'état de ce point de vue, et de transmettre le point de vue englobante à -[NSStatusItem setView:]. Voici ma mise en œuvre.

Dans 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 {}
…

J'ai ajouté une méthode personnalisée, -[NSView center], qui effectue les opérations suivantes:

@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

Autres conseils

Je vous ai vu résolu le problème que je quitterai c'est une alternative à votre mise en œuvre. Vous pouvez utiliser ProgressHud.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top