我在视图中有这个手势代码
- (void)rightSwipeHandle:(UIPanGestureRecognizer*)gestureRecognizer{
CGPoint touchBegan;
CGPoint pointEnd;
if (gestureRecognizer.state == UIGestureRecognizerStateBegan)
{
CGPoint touchBegan = [gestureRecognizer locationInView: gestureRecognizer.view];
NSLog(@"pointBegan:%@",NSStringFromCGPoint(touchBegan));
}
else if (gestureRecognizer.state == UIGestureRecognizerStateChanged)
{
}
else if (gestureRecognizer.state == UIGestureRecognizerStateEnded ||
gestureRecognizer.state == UIGestureRecognizerStateCancelled ||
gestureRecognizer.state == UIGestureRecognizerStateFailed)
{
pointEnd = [gestureRecognizer locationInView:gestureRecognizer.view];
NSLog(@"pointEnd:%@", NSStringFromCGPoint(pointEnd));
CGFloat xDist = (pointEnd.x - touchBegan.x);
CGFloat yDist = (pointEnd.y - touchBegan.y);
CGFloat distance = sqrt((xDist * xDist) + (yDist * yDist));
NSLog(@"distance:%f", distance);
}
}
但它不能正常工作,我不知道问题出在哪里......如果滑动是从底部到顶部,它会计算一个距离,如果你做相反的事情,它会计算一个很大的不同距离,我不不明白