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

2018-08-29  本文已影响0人  yangli

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];
    
}
上一篇下一篇

猜你喜欢

热点阅读