点击屏幕,获取屏幕上的坐标

点击屏幕,获取屏幕上的坐标

直接上代码:


//当有一个或多个手指触摸事件在当前视图或window窗体中响应
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSSet *allTouches = [event allTouches];    //返回与当前接收者有关的所有的触摸对象
    UITouch *touch = [allTouches anyObject];   //视图中的所有对象
//返回触摸点在视图中的当前坐标,
   // CGPoint point = [touch locationInView:[touch view]]; 
    CGPoint point = [touch locationInView:[touch window]]; //返回触摸点在window中的当前坐标
    CGFloat x = point.x;
    CGFloat y = point.y;
    NSLog(@"touch (x, y) is (%f, %f)", x, y);
}
如果想获取手指在屏幕滑动一连串坐标请参考

点击参考

如果文章帮到您,喜欢点个赞,谢谢您。
文章内容出错,记得留言,感激不尽。

你可能感兴趣的:(点击屏幕,获取屏幕上的坐标)