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

2022-08-09  本文已影响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));
上一篇 下一篇

猜你喜欢

热点阅读