Here's another NSWindow question ... I have a borderless window that is transparent, which is created this way ...
- (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; }
... and viewFrameDidChange: defined as ...
- (void)viewFrameDidChange:(NSNotification *)note { if ( note.object != self.contentView ) { return; } [self display]; [self setHasShadow:NO]; [self setHasShadow:YES]; }
... this is the only way to have the correct shadow NSWindow . In other words, whenever the window is resized, I have to call display , setHasShadow:NO and setHasShadow:YES , otherwise the window shadow is crippled - it's not around the whole window - only part of the window, etc.
This works until I start the height animation. If the height is animated, the shadow is correctly recounted and displayed, but the whole window and shadow flicker, and it's pretty ugly.
The idea why the shadow flickers? I tried replacing display , setHasShadow:NO/YES with [self invalidateShadow] , but it does not work at all, and the shadow does not display correctly.
How to avoid window height animation with shadow in unlimited / transparent window?
Here is a video of the shimmering shadow. http://d.pr/v/lbkQ
objective-c cocoa nswindow
robertvojta
source share