Abr*_*egh 5 cocoa objective-c nsprogressindicator
当我在执行动作时创建NSProgressIndicator并使用NSStatusItem's -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];
Run Code Online (Sandbox Code Playgroud)
不要缩放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 {}
…
Run Code Online (Sandbox Code Playgroud)
我添加了一个自定义方法-[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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1351 次 |
| 最近记录: |