- (voID)drawRect:(NSRect)dirtyRect { if ([[self window] isKeyWindow]) { NScolor *startingcolor = [NScolor colorWithCalibrateDWhite:0.8 Alpha:1.0]; NScolor *endingcolor = [NScolor colorWithCalibrateDWhite:0.6 Alpha:1.0]; NSGradIEnt* aGradIEnt = [[NSGradIEnt alloc] initWithStartingcolor:startingcolor endingcolor:endingcolor]; [aGradIEnt drawInRect:[self bounds] angle:270]; } else { NScolor *startingcolor = [NScolor colorWithCalibrateDWhite:0.9 Alpha:1.0]; NScolor *endingcolor = [NScolor colorWithCalibrateDWhite:0.8 Alpha:1.0]; NSGradIEnt* aGradIEnt = [[NSGradIEnt alloc] initWithStartingcolor:startingcolor endingcolor:endingcolor]; [aGradIEnt drawInRect:[self bounds] angle:270]; } [super drawRect:dirtyRect];}解决方法 我认为您所看到的行为是因为窗口不一定会重新绘制,因为它会获得或失去关键状态.我会尝试在窗口变为或重置密钥时强制更新窗口.就像是:
- (voID) vIEwDIDMovetoWindow{ if( [self window] == nil ) { [[NSNotificationCenter defaultCenter] removeObserver:self]; } else { [[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(forceUpdate) name:NSWindowDIDResignKeyNotification object:[self window]]; [[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(forceUpdate) name:NSWindowDIDBecomeKeyNotification object:[self window]]; }}- (voID) forceUpdate{ [self setNeedsdisplay:YES];}总结
以上是内存溢出为你收集整理的可可 – 带渐变填充的NSView?全部内容,希望文章能够帮你解决可可 – 带渐变填充的NSView?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)