Is it possible to compare touch coordinates made by the users on the UIView to the one store in a plist or txt format? The argument looks like this;
if (user touch coordinate == touch coordinate stored in plist or text)
then
(do something)
else
(do something)
If possible in what format should i write the coordinates in the list and how to associate it inside the program?
thanks in advance and sorry if you find my question a bit noobie.
Best Solution
Not sure if there's a one-liner solution.
On a UITouch instance, the
locationInView:
method returns a CGPoint struct (x and y coordinates, both of type float). So you can store the x and y coordinates in your plist, then compare them with your current touch's x and y coordinates.EDIT: Also, when comparing the coordinates, you probably want to use the distance between the two points to determine when you have a "hit".
EDIT: Below is sample code for loading and writing to a property list, where the values are based on a NSDictionary:
The method to calculate the distance between the two locations of the UITouches:
And finally, the code that uses the values in the property list to determine if the user hit the previous location: