0

I am able to find the x,y location on the iPhone screen using a method similar to: How to get a CGPoint from a tapped location?. However, since TouchesBegan and TouchesEnded require void, I am unable to return there locations directly and use in a different method to calculate the distance. The distance method I am trying to use is:

- (CGFloat) calculateDistanceBetweenPoint1: (CGPoint)start point2:(CGPoint)end
{
    CGFloat dx = end.x - start.x;
    CGFloat dy = end.y - start.y;
    return sqrt(dx*dx + dy*dy);
}

where end is the coordinate using touchesEnded and start is the coordinate using touchesBegan. Once I find the distance in pixels I will then convert it to inches or centimeters. Any suggestions?

Community
  • 1
  • 1
  • 1
    "return there locations directly"?? what do you mean? why not just save the value in a ivar – Bryan Chen Jun 13 '13 at 00:18
  • Under both the -(void)touchesBegan... and -(void)touchesEnded methods the locations are saved as currentLoc.location.x and currentLoc.location.y, where location is a CGPoint. I want to use these locations in the method entered in my question. I am new to objective-c and I am continually getting "Unused variable" errors or hiding instance variable errors. Can you give an example of what I should declare in my header file and how I should implement the ivar? Note, all 3 of these methods are in the same class file. I would really appreciate it! – user2480376 Jun 17 '13 at 13:29

0 Answers0