点击屏幕,获取屏幕上的坐标
直接上代码:
//当有一个或多个手指触摸事件在当前视图或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);
}
如果想获取手指在屏幕滑动一连串坐标请参考