这是另一个NSWindow
问题......我有无边框窗口,透明,以这种方式创建......
- (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;
}
...并被viewFrameDidChange:
定义为...
- (void)viewFrameDidChange:(NSNotification *)note {
if ( note.object != self.contentView ) {
return;
}
[self display];
[self setHasShadow:NO];
[self setHasShadow:YES];
}
...这是获得适当NSWindow
阴影的唯一方法。换句话说,每当窗口大小发生变化时,我都必须调用,display
否则窗口阴影会被削弱 - 它不在整个窗口周围 - 只是窗口的一部分,等等。setHasShadow:NO
setHasShadow:YES
在我开始动画高度之前,这确实有效。如果高度是动画的,阴影会正确地重新计算和显示,但整个窗口和阴影会闪烁并且非常难看。
一个想法为什么阴影在闪烁?我尝试将 , 替换display
为setHasShadow:NO/YES
,[self invalidateShadow]
但它根本不起作用,并且阴影以错误的方式显示。
如何在无边框/透明窗口中使用阴影为窗口高度设置动画以避免闪烁?
这是闪烁阴影的视频。http://d.pr/v/lbkQ