这就是我创建nsprogressIndicator和 采用 NSStatusItem' -setView: 方法 在我执行动作时,要在梅巴尔地区展示它:

混乱的nsprogressIndicator http://cl.ly/l9r/content的示例

是什么原因导致该边界显示,如何将其删除?预期的结果是控制是透明的。

这是我正在使用的代码:

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];
有帮助吗?

解决方案

不要缩放 NSProgressIndicator 虽然这也是 NSView. 。创建一个新的视图,调整良好大小,将状态指标定位在该视图中,然后将封闭视图传递给 -[NSStatusItem setView:]. 。这是我的实施。

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

我添加了一种自定义方法 -[NSView center], ,以下执行以下操作:

@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

其他提示

我已经看到您解决了我将留下的问题,这是您实施的替代方法。您可以使用 Progresshud.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top