美文网首页
ios ~ 手指在view或window上的位置 x、y

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

作者: 阳光下的叶子呵 | 来源:发表于2022-08-09 18:59 被阅读0次

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

所求的自定义view:self.lineLayerRangeView

- (void)touchesBegan:(NSSet<UITouch *> *)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<UITouch *> *)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<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesEstimatedPropertiesUpdated:(NSSet<UITouch *> *)touches API_AVAILABLE(ios(9.1));

相关文章

网友评论

      本文标题:ios ~ 手指在view或window上的位置 x、y

      本文链接:https://www.haomeiwen.com/subject/fnwnwrtx.html