ios – 为什么 – [UIColor setFill]的工作没有指向绘图上下文?

它逃脱了我为什么这个代码,在drawRect :,工作原理:
UIBezierPath *buildingFloor = [[UIBezierPath alloc] init];
// draw the shape with addLineToPoint
[[UIColor colorWithRed:1 green:0 blue:0 alpha:1.0] setFill]; // I'm sending setFill to UIColor object?
[buildingFloor fill]; // Fills it with the current fill color

我的观点是,UIColor对象获取一个消息setFill然后不知何故堆栈了解这个UIColor现在将是填充颜色,这不是奇怪的和错误的?至少我会期望通过调用一些CGContext方法来设置填充…但现在,而不是表示一个颜色,UIColor继续,并做一些改变我的图形的上下文.

有人可以解释幕后发生的事情,因为我完全迷失在这里吗?

我在发布之前查看了这些参考资料:

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIColor_Class/Reference/Reference.html
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIBezierPath_class/Reference/Reference.html

解决方法

My point is,UIColor object gets a message setFill and then somehow the stack understands that this UIColor will now be the fill color,isn’t this just weird and wrong? At the very least I would expect setting fill by calling some CGContext method… But now instead of representing a color,UIColor goes on and does something to change the context of my drawing.

这是因为所有这一切都是在当前的CGContext中进行的.这就是为什么你的代码只有当有一个当前的CGContext(例如在drawRect或UIGraphicsBeginImageContextWithOptions块中)时才工作.

这可能会帮助您,在iOS研究的这个阶段,阅读我的书:http://www.apeth.com/iOSBook/ch15.html#_graphics_contexts的绘图章节

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...