Transparent NSWindow on OSX El Capitan

Prior to El Capitan, this code worked exactly as it should. Now my window is no longer transparent, it is white.

 NSWindow* window = [[NSWindow alloc] initWithContentRect:rect styleMask:NSBorderlessWindowMask backing:NSBackingStoreNonretained defer:NO];
 [window setOpaque:NO];
 [window setBackgroundColor:[NSColor clearColor]];

Any ideas? Thanks for the help.

+4
source share
1 answer

I'm not sure where you put the code, but it worked for me.

  • Subclass NSWindow
  • Paste the following code:

-

- (id)initWithContentRect:(NSRect)contentRect
            styleMask:(NSUInteger)aStyle
              backing:(NSBackingStoreType)bufferingType
                defer:(BOOL)flag {

    // Using NSBorderlessWindowMask results in a window without a title bar.
    self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
    if (self != nil) {        
        // Start with no transparency for all drawing into the window
        [self setAlphaValue:1.0];
        //Set backgroundColor to clearColor
        self.backgroundColor = NSColor.clearColor;
        // Turn off opacity so that the parts of the window that are not drawn into are transparent.
        [self setOpaque:NO];
    }
    return self;
 }

This code is on the apple sample page - Round Transparent Window

You used NSBackingStoreNonretainedas window support. According to the docs:

. Classic Blue Box. , - .. , . , .

.

+4

Source: https://habr.com/ru/post/1611746/


All Articles