我已经可以在 touchesMoved 中检测到滑动动作,但我想知道如何检测滑动,然后检测滑动停止但手指仍按在屏幕上的时间?
到目前为止,这是我的代码:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if(self.tutorialView.alpha != 1.0 || self.tutorialView.hidden)
{
UITouch *touch = [touches anyObject];
CGPoint gestureEndPoint = [touch locationInView:self.view];
int dx = abs(gestureStartPoint.x - gestureEndPoint.x);
int dy = -1 * (gestureEndPoint.y - gestureStartPoint.y);
if(dx > 20) {
// too much left/right, so don't do anything
return;
}
if((gestureStartPoint.x - gestureEndPoint.x) < 20 && (gestureStartPoint.x - gestureEndPoint.x) > -20)
{
if((gestureStartPoint.y - gestureEndPoint.y) > (gestureStartPoint.x - gestureEndPoint.x))
{
if(dy > 0)
{
// User has made an upwards slide motion
}
else
{
// User has made a downwards slide motion
else
self.number = 0;
}
}
}
}
}