xcode iphone触摸点画

发布于 2024-10-18 02:54:02 字数 791 浏览 3 评论 0原文

大家好,我是法国人,请原谅我的英语。我的问题是我想用我的手指在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情泪▽动烟 2024-10-25 02:54:02

CGContextSetLineDash

http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html%23//apple_ref/c/func/CGContextSetLineDash

示例:

CGFloat dashes[] = { 1, 1 };
CGContextSetLineDash( context, 0.0, dashes, 2 );

或者只需在 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:

CGFloat dashes[] = { 1, 1 };
CGContextSetLineDash( context, 0.0, dashes, 2 );

Or simply open QuartzDemo sample in Xcode and look at QuartzLines.m file (QuartzDashView class).

You should really read documentation (see already mentioned link).

流云如水 2024-10-25 02:54:02

您的问题是您在执行此操作之前没有引用上下文: 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

青瓷清茶倾城歌 2024-10-25 02:54:02

请参阅有关线路属性的作用的精彩页面!
https://horseshoe7.wordpress.com/2014/ 07/16/core-graphics-line-drawing-explained/

根据上面的页面,这里是“点”线的代码,如 ( . . . . )

// should
CGContextSetLineCap(context, kCGLineCapRound);

// please see the role of line properties why the first should be 0 and the second should be the doulbe of the given line width
CGFloat dash[] = {0, lineWidth*2};

// the second value (0) means the span between sets of dot patterns defined by dash array
CGContextSetLineDash(context, 0, dash, 2);

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 ( . . . .)

// should
CGContextSetLineCap(context, kCGLineCapRound);

// please see the role of line properties why the first should be 0 and the second should be the doulbe of the given line width
CGFloat dash[] = {0, lineWidth*2};

// the second value (0) means the span between sets of dot patterns defined by dash array
CGContextSetLineDash(context, 0, dash, 2);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文