在iPhone / iPad上画一条线 [英] Drawing a line in iPhone / iPad

查看:183
本文介绍了在iPhone / iPad上画一条线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发一个应用程序,当用户可以绘制线条时......但我不想绘制直线,但想要在用户绘制线条时显示线条。当用户从A点到BI想要拉直线时(如果用户需要的话)。

为了能够做到这一点,我想改变我的观点从0,0(左上角)到320,480(iPhone)和768,1024(iPad)(右下角)开始。

问题我有10,10点的A点和100,100点的B点。

我的问题:

- 如何创建这个网格?<
- 如何创建这些点?

- 如何绘制这条线而不拉直它?

- 如何绘制拉直线?



我的问题是我熟悉创建普通UI应用程序。我不熟悉Open-GL等。



我希望有人能帮助我。



Best关于,
Paul Peelen

解决方案

您将 UIView 并覆盖 - (void)drawRect:(CGRect)rect 方法。

获取图形上下文:

  CGContextRef context = UIGraphicsGetCurrentContext(); 

你可以使用它来进行Core Graphics调用,例如:

  CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextBeginPath(context); (k = 0; k< count; k + = 2){
CGContextMoveToPoint(context,s [k] .x,s [k] .y);
;
CGContextAddLineToPoint(context,s [k + 1] .x,s [k + 1] .y);
}
CGContextStrokePath(context);

查看Quartz 2D Programming Guide了解所有细节。


I would like to develop an app when the user can draw lines... but I do not want to draw straight lines but want to show the line as the users draws it. When the user gets from point A to B I would like to straighten the line (if the users wants this).

To be able to do this I want to change my view into a grid starting at 0,0 (top left) and ending at 320,480 (for iPhone) and 768,1024 (for iPad) (bottom right).

For this question I have point A at 10,10 and point B at 100,100.

My question:
- How do I create this grid?
- How do I create these points?
- How do I draw this line without straightening it?
- How do I draw the straighten line?

My problem is that I am familiar with creating "normal" UI apps. I am not familiar with Open-GL ect.

I hope someone can help me with this.

Best regards,
Paul Peelen

解决方案

You subclass your UIView and override the - (void)drawRect:(CGRect)rect method.

In there you grab a graphics context:

CGContextRef context = UIGraphicsGetCurrentContext();

And you use that to make Core Graphics calls, like:

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextBeginPath (context);
for (k = 0; k < count; k += 2) {
    CGContextMoveToPoint(context, s[k].x, s[k].y);
    CGContextAddLineToPoint(context, s[k+1].x, s[k+1].y);
}
CGContextStrokePath(context);

Look up the Quartz 2D Programming Guide for all the details.

这篇关于在iPhone / iPad上画一条线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆