0

I have created a secondary NSViewController to create a progress indicator "popup". The reason for this is that the software has to interact with some hardware and some of the functions take the device a few seconds to respond. So being thoughtful of the end user I have a NSViewController that has a NSView (that is black and semi-transparent) and then a message/progress bar on top. This is added to the window using addSubView.

Everything works great except when the screen has a NSTextField in it. The popup shows but the NSTextField is drawn on top. What is this?

The view code I used for drawing semi-transparent:

@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

The code I use to show the progress view

-(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];
}

Is there a better way to add the subview or to tell the NSTextFields I don't want them to be drawn on top?

Thanks!

Andriy
  • 2,767
  • 2
  • 21
  • 29
David Nelson
  • 752
  • 1
  • 10
  • 27

1 Answers1

0

So Setting [self setWantsLayer] to my custom NSViews sort of worked however there are a lot of redraw issues (white borders, and backgrounds). A NSPopover may be better in some instances however I was going for "locked down" approach where the interface is unreachable until it finishes (or times out).

What worked for me was to go to the instance of my NSView, select the window in Interface Builder, then go to layers (far right on properties view) and select my view under "Core Animation Layer".

David Nelson
  • 752
  • 1
  • 10
  • 27