gpt4 book ai didi

objective-c - 是什么导致白色边框应用于系统菜单中显示的 NSProgressIndicator?

转载 作者:太空狗 更新时间:2023-10-30 03:53:01 25 4
gpt4 key购买 nike

这是我创建 NSProgressIndicator 和 use NSStatusItem's -setView: method 时发生的情况在我执行操作时将其显示在菜单栏区域:

Example of messed up 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。创建一个可以很好地调整大小的新 View ,将状态指示器放置在该 View 中,并将封闭 View 传递给 -[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

关于objective-c - 是什么导致白色边框应用于系统菜单中显示的 NSProgressIndicator?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2714951/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com