作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
因为我有 CustomView
,我想在其中检测 Touch Event
,就像当用户执行 Touch
向下/向上和释放或反之亦然时一样这张图片。
我尝试过的
滑动但在其中我只获取用户松开手指的坐标。比如点击 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/
我是一名优秀的程序员,十分优秀!