gpt4 book ai didi

ios - 如何用坐标检测手指从上到下/从下到上

转载 作者:行者123 更新时间:2023-11-28 22:31:47 25 4
gpt4 key购买 nike

因为我有 CustomView,我想在其中检测 Touch Event,就像当用户执行 Touch 向下/向上和释放或反之亦然时一样这张图片。

enter image description here

我尝试过的

滑动但在其中我只获取用户松开手指的坐标。比如点击 X = 100 并在 10 上释放,我只得到 10

我在找什么

想要获得整个坐标,例如用户点击 X = 100 并在 X = 80 上释放,然后寻找每个坐标变化,例如 100,99 ,98,97,96,95,94.......80. 与手指移动一样。

请如果有人对此有任何想法或我忘记做的事情。请审核。

最佳答案

将此更改为您的 .h 文件

@interface ViewController : UIViewController{
CGFloat touchStartPoint;
CGFloat touchOffsetPoint;
CGFloat tempTouchOffsetPoint;
}

@end

然后将此添加到您的 .m 文件

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch=[touches anyObject];
touchStartPoint=[touch locationInView:self.view].y;
touchOffsetPoint = 0;
tempTouchOffsetPoint = 0;
// NSLog(@"touchStartPoint = %f",touchStartPoint);
}


-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch=[touches anyObject];
touchOffsetPoint = [touch locationInView:self.view].y - touchStartPoint;


if (touchOffsetPoint>tempTouchOffsetPoint) {
NSLog(@"touch down");
}else{
NSLog(@"touch up");
}

tempTouchOffsetPoint = touchOffsetPoint;
}

关于ios - 如何用坐标检测手指从上到下/从下到上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17212723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com