Note that there are some explanatory texts on larger screens.

plurals
  1. PONSWindow - borderless, transparent window - flickering shadow when animating window height
    text
    copied!<p>Here's another <code>NSWindow</code> question ... I've got borderless window, transparent, which is created in this way ...</p> <pre><code>- (id)initWithView:(NSView *)view anchorPoint:(NSPoint)anchorPoint position:(NSPoint)position distance:(CGFloat)distance { if ( !view ) { return nil; } NSSize size = view.intrinsicContentSize; NSRect contentRect = NSMakeRect( 0, 0, size.width, size.height ); self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]; if ( !self ) { return nil; } _windowView = view; _anchorPoint = anchorPoint; _position = position; _distance = distance; [self setContentView:_windowView]; [self setExcludedFromWindowsMenu:YES]; [self setMovableByWindowBackground:NO]; [self setOpaque:NO]; [self setBackgroundColor:[NSColor clearColor]]; [self setHasShadow:YES]; [self useOptimizedDrawing:YES]; [self setReleasedWhenClosed:NO]; [self setFrame:[self windowRectWithSize:contentRect.size] display:YES]; [self setAnchorAttribute:NSLayoutAttributeTop forOrientation:NSLayoutConstraintOrientationVertical]; [self setAnchorAttribute:NSLayoutAttributeCenterX forOrientation:NSLayoutConstraintOrientationHorizontal]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewFrameDidChange:) name:NSViewFrameDidChangeNotification object:nil]; return self; } </code></pre> <p>... and <code>viewFrameDidChange:</code> is defined as ...</p> <pre><code>- (void)viewFrameDidChange:(NSNotification *)note { if ( note.object != self.contentView ) { return; } [self display]; [self setHasShadow:NO]; [self setHasShadow:YES]; } </code></pre> <p>... this is the only way to have proper <code>NSWindow</code> shadow. In other words, whenever window size changes, I have to call <code>display</code>, <code>setHasShadow:NO</code> and <code>setHasShadow:YES</code> otherwise the window shadow is crippled - it's not around the whole window - just part of the window, etc.</p> <p>This does work until I start animating height. If height is animated, shadow is correctly recalculated and displayed, but the whole window &amp; shadow is flickering and it's pretty ugly.</p> <p>An idea why the shadow is flickering? I tried to replace <code>display</code>, <code>setHasShadow:NO/YES</code> with <code>[self invalidateShadow]</code>, but it doesn't work at all and shadow is displayed in a wrong way.</p> <p>How one should animate window height with shadow in borderless/transparent window to avoid flickering?</p> <p>Here's the video of the flickering shadow. <a href="http://d.pr/v/lbkQ" rel="noreferrer">http://d.pr/v/lbkQ</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload