I have an image shown on my screen, and I want to be able to select any part of the image and get the (x,y) coordinates of that point and show a Label with a dot where I touched and the coordinates right next to it.
My problem is this. I can touch and change the coordinates text appropriately, but it isn't moving the actual location of the Label on the first touch. It does move to the appropriate place if I touch in the exact same place twice. If I touch somewhere only once though, it will move it back to the original place that it was created.
Here is the code block I use for the touch:
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:nil];
_coordinatesLabel.center = CGPointMake(location.x + 83, location.y - 4);
_coordinatesLabel.text = [NSString stringWithFormat:@"• (%.2f,%.2f)", location.x/32, (768-location.y)/32];
}
Edit
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:nil];
_coordinatesLabel.translatesAutoresizingMaskIntoConstraints = true;
_coordinatesLabel.center = CGPointMake(location.x + 83, location.y - 4);
_coordinatesLabel.text = [NSString stringWithFormat:@"• (%.2f,%.2f)", location.x/32, (768-location.y)/32];
}
I add that middle line of code and it works perfectly. Thanks for the help.