我正在使用tap事件是非常时间敏感的,所以我很好奇是否有可能在用户简单触摸时激活UITapGestureRecognizer,而不是要求它们也能触摸起来?
我试图检测触摸运动的速度,我并不总是得到我期望的结果.(补充说:速度太快了)如果我正在做一些时髦或建议更好的方法,有人能发现吗?
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
self.previousTimestamp = event.timestamp;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self.view];
CGPoint prevLocation = [touch previousLocationInView:self.view];
CGFloat distanceFromPrevious = distanceBetweenPoints(location,prevLocation);
NSTimeInterval timeSincePrevious = event.timestamp - self.previousTimestamp;
CGFloat speed = distanceFromPrevious/timeSincePrevious;
self.previousTimestamp = event.timestamp;
NSLog(@"dist %f | time %f | speed %f",distanceFromPrevious, timeSincePrevious, speed);
}
Run Code Online (Sandbox Code Playgroud)