该窗口的内容视图在IB中设置为绘制窗口背景的自定义类.
这是代码:
- (voID)drawRect:(NSRect)dirtyRect{ [NSGraphicsContext saveGraphicsstate]; float cornerRadius = 10; NSBezIErPath *path = [NSBezIErPath bezIErPathWithRoundedRect:self.bounds xRadius:cornerRadius yRadius:cornerRadius]; [path setClip]; NSGradIEnt *gradIEnt = [[NSGradIEnt alloc] initWithcolorsAndLocations: [NScolor colorWithCalibratedRed:0.96f green:0.96f blue:0.96f Alpha:1.00f],0.0f,[NScolor colorWithCalibratedRed:0.84f green:0.84f blue:0.84f Alpha:1.00f],1.0f,nil]; [gradIEnt drawInRect:self.bounds angle:270]; [NSGraphicsContext restoreGraphicsstate];}
它会导致一些非常奇怪的工件,比如消失的对象或文本字段的背景变为窗口:
这是怎么回事?我试图隔离它,我一直在玩这个“图形上下文状态保存”的东西(我不确定我是否理解正确),但问题仍然存在.
我有XCode 4.4,SDK是10.7(我的 *** 作系统也是如此),部署目标是10.6.这可能没关系,但过去我一直在做类似的事情,我从未遇到过这样的奇怪问题.
解决方法 问题似乎是[path setClip]方法.我评论了这一点,文本字段和按钮正确绘制.所以,我接着换了一行:
[gradIEnt drawInRect:self.bounds angle:270];
同
[gradIEnt drawInBezIErPath:path angle:270];
一切都很完美.按钮和文本字段按预期显示.
NSBezIErPath的类引用声明:
You should avoID using this method as a way of adjusting the clipPing path,as it may expand the clipPing path beyond the bounds set by the enclosing vIEw. If you do use this method,be sure to save the graphics state prior to modifying the clipPing path and restore the graphics state when you are done.
This method uses the current winding rule to determine the clipPing shape of the receiver. This method does not affect the receiver’s path.
没有真正解释你看到的问题,但引导我看看我怎么能画出渐变.
总结以上是内存溢出为你收集整理的objective-c – 在Cocoa的窗口圆角渐变背景全部内容,希望文章能够帮你解决objective-c – 在Cocoa的窗口圆角渐变背景所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)