0

I am working on an iPad app, and one of the features that has been requested is the ability to make measurements of an image. With the knowledge that the iPad screen has a 132ppi resolution, it seems as though it will be quite simple to implement this.

But how can I draw a straight line on the iPad? Is there a library that is best? Is core animation, open gl, or quartz what I need? I don't have any experience drawing anything, so if someone can just be like "do this", I'll go figure out how to do it. I want to make it so the user can't draw anything but a straight line, and then when they are done, I need to know how many pixels long the line is.

Please help. Thanks

EDIT I forgot to make this clear, I would like to be able to make it so the line is drawn as the user goes. So they put the finger down, and then maybe a little dot appears, then as they drag, the line gets linger, and when they stop, the line is done.

Stephen J.
  • 3,127
  • 4
  • 20
  • 28

2 Answers2

0

Please see this answer:

How do I draw a line on the iPhone?

Also, to get the length, implement touchesBegan and touchesEnded, record both CGPoints and calculate the delta.

Community
  • 1
  • 1
Oh Danny Boy
  • 4,857
  • 8
  • 56
  • 88
0

The distance formula

In code:

 CGFloat dx = point2.x - point1.x;
 CGFloat dy = point2.y - point1.y;
 CGFloat distance = sqrt(dx*dx + dy*dy);
Todd Hopkinson
  • 6,803
  • 5
  • 32
  • 34