xcode iphone触摸点画
大家好,我是法国人,请原谅我的英语。我的问题是我想用我的手指在iPhone上画一个像这样的点画---------,不是一条线而是一个画。我有:
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //kCGLineCapSquare, kCGLineCapButt, kCGLineCapRound
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0); // for size
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 1.0, 0.0, 1.0); //values for R, G, B, and Alpha
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
请问“点”的代码是什么。
HI every body I'm french so scuse me for my english. My problem is that I want to draw with my finger on the iphone a dotted drawing like that -----------, not a line but a draw.I have :
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //kCGLineCapSquare, kCGLineCapButt, kCGLineCapRound
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0); // for size
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 1.0, 0.0, 1.0); //values for R, G, B, and Alpha
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
What is the code for "dotted" please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
CGContextSetLineDash
http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html%23//apple_ref/c/func/CGContextSetLineDash
示例:
或者只需在 Xcode 中打开 QuartzDemo 示例并查看 QuartzLines.m 文件(QuartzDashView 类)。
您应该真正阅读文档(请参阅已经提到的链接)。
CGContextSetLineDash
http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html%23//apple_ref/c/func/CGContextSetLineDash
Example:
Or simply open QuartzDemo sample in Xcode and look at QuartzLines.m file (QuartzDashView class).
You should really read documentation (see already mentioned link).
您的问题是您在执行此操作之前没有引用上下文: CGContextSetLineDash( context, 0.0, dashes, 2 );
您需要执行以下操作:
CGContextRef context = UIGraphicsGetCurrentContext();
,然后用上下文替换所有 UIGraphicsGetC... 调用,以加快速度。Deitel 的《iPhone 应用程序驱动方法》一书中有一个这样做的示例。
格斗S
Your problem is you did not reference the context before doing this: CGContextSetLineDash( context, 0.0, dashes, 2 );
You need to do this:
CGContextRef context = UIGraphicsGetCurrentContext();
then replace all your UIGraphicsGetC... calls with context, to speed it up anyway.Deitel's iPhone App-Driven Approach book has an example of doing this.
FightingS
请参阅有关线路属性的作用的精彩页面!
https://horseshoe7.wordpress.com/2014/ 07/16/core-graphics-line-drawing-explained/
根据上面的页面,这里是“点”线的代码,如 ( . . . . )
See the great page about the roles of line properties!
https://horseshoe7.wordpress.com/2014/07/16/core-graphics-line-drawing-explained/
According to the above page, here is the code for the 'dot' line like ( . . . .)