【发布时间】:2014-03-20 08:00:38
【问题描述】:
我创建了辅助NSViewController 来创建进度指示器“弹出窗口”。原因是软件必须与某些硬件交互,并且某些功能需要设备几秒钟才能响应。因此,考虑到最终用户,我有一个NSViewController,它有一个NSView(黑色和半透明),然后是顶部的消息/进度条。这是使用addSubView 添加到窗口中的。
除了屏幕上有NSTextField 之外,一切都很好。弹出窗口显示,但 NSTextField 绘制在顶部。这是什么?
我用于绘制半透明的视图代码:
@implementation ConnectingView
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];
// Drawing code here.
CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
CGContextSetRGBFillColor(context, 0.227,0.251,0.337,0.8);
CGContextFillRect(context, NSRectToCGRect(dirtyRect));
}
@end
我用来显示进度视图的代码
-(void) showProgressWithMessage:(NSString *) message andIsIndet:(BOOL) indet
{
connectingView = [[ConnectingViewController alloc] init];
[self.view.window.contentView addSubview:connectingView.view];
connectingView.view.frame = ((NSView*)self.view.window.contentView).bounds;
[connectingView changeProgressLabel:message];
if (indet)
[connectingView makeProgressBar:NO];
}
有没有更好的方法来添加子视图或告诉NSTextFields我不希望它们被绘制在顶部?
谢谢!
【问题讨论】:
-
您是否考虑过使用
NSPopover来显示此进度?它可能会产生更好的结果。 -
你设置WantsLayer了吗?
标签: macos cocoa nsview nstextfield