Get touch coordinates (in the form of 0-480 and 0-320)

I do not understand how to translate the coordinates of the iphone.

If I make one touch, I will get the coordinate.

if I touch and save it and let it go, it shows the difference between the start and end points.

How to get the absolute touch position?

thanks!

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:touch.view];
    NSLog(@"X: %f",location.x);
    NSLog(@"Y: %f",location.y);
}

I want to resize an image by touching and dragging (height only)

+5
source share
1 answer

The touch position is calculated relative to the view.

If you want the position relative to the screen to be:

UITouch * touch = [touches anyObject];
CGPoint pos = [touch locationInView: [UIApplication sharedApplication].keyWindow];
NSLog(@"Position of touch: %.3f, %.3f", pos.x, pos.y);

(dry encoding, may lead to errors)

+11
source

All Articles