views:

1376

answers:

1

i dont get how to translate the coordinates of the iphone.

if i make a single touch i get the coordinate.

if i make a touch and keep it and release it it shows the difference of the starting and end point.

how do i get the absolute position of the touch?

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 with touch and drag(only the height)

+1  A: 

The position of a touch is calculated relative to a view.

If you want the position relative to the screen do:

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

(dry coded, might give errors)

nash
thank you!How is it possible to resize an UIImageVIew by dragging one side?
jacky
I've never used the UIImage classes. Have a look at the UIImage class refernce: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html . More specifically at `drawInRect:`
nash