ios ~ 手指在view或window上的位置 x、y

获取手指在某一个UIView上的具体位置:point.xpoint.y

所求的自定义view:self.lineLayerRangeView

- (void)touchesBegan:(NSSet *)touches withEvent:(nullable UIEvent *)event {
    UITouch *touch = touches.anyObject;
    CGPoint point = [touch locationInView:self.lineLayerRangeView];
    
    NSLog(@"☺️☺️☺️ 开始触摸屏幕 手指所在 view上的位置 point.X ==== %f,\n point.Y ==== %f", point.x, point.y);
}

- (void)touchesMoved:(NSSet *)touches withEvent:(nullable UIEvent *)event {
// iOS 怎么样获取手指在view上滑动的起点坐标与终点坐标
    UITouch *touch = touches.anyObject;
    CGPoint point = [touch locationInView:self.lineLayerRangeView];
    
    NSLog(@" 手指所在 view上的位置 point.X ==== %f,\n point.Y ==== %f", point.x, point.y);
}
相关系统方法:
// Generally, all responders which do custom touch handling should override all four of these methods.
// Your responder will receive either touchesEnded:withEvent: or touchesCancelled:withEvent: for each
// touch it is handling (those touches it received in touchesBegan:withEvent:).
// *** You must handle cancelled touches to ensure correct behavior in your application.  Failure to
// do so is very likely to lead to incorrect behavior or crashes.
- (void)touchesBegan:(NSSet *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesEstimatedPropertiesUpdated:(NSSet *)touches API_AVAILABLE(ios(9.1));

你可能感兴趣的:(ios ~ 手指在view或window上的位置 x、y)