获取触摸坐标(格式为0-480和0-320) [英] get touch coordinates (in the form of 0-480 and 0-320)

查看:63
本文介绍了获取触摸坐标(格式为0-480和0-320)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何转换iphone的坐标.

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?

谢谢!

-(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)

推荐答案

相对于视图计算触摸的位置.

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)

这篇关于获取触摸坐标(格式为0-480和0-320)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆