Object-C中获取当前触摸点的坐标位置

touches

//当有一个或多个手指触摸事件在当前视图或window窗体中响应
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];   //视图中的所有对象
    CGPoint point = [touch locationInView:self.view]; //返回触摸点在视图中的当前坐标
    int x = point.x;
    int y = point.y;
    NSLog(@"touch (x, y) is (%d, %d)", x, y);
}

UITapGestureRecognizer 获取点击位置

-(void)handleSingleTap:(UITapGestureRecognizer *)sender
{
    CGPoint touchPoint = [sender locationInView:self.view];
    
}

你可能感兴趣的:(Object-C中获取当前触摸点的坐标位置)