如何获得touchmoved功能中手指运动的速度和方向?UITouch touchesMoved手指方向和速度
我想获取手指速度和手指方向,并将其应用于UIView类的方向移动和动画速度。
我看了这个链接,但我不明白的答案,除了它没有解释如何检测方向:
UITouch movement speed detection
到目前为止,我试过这段代码:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *anyTouch = [touches anyObject];
CGPoint touchLocation = [anyTouch locationInView:self.view];
//NSLog(@"touch %f", touchLocation.x);
player.center = touchLocation;
[player setNeedsDisplay];
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 = [self distanceBetweenPoints:location :prevLocation];
NSTimeInterval timeSincePrevious = event.timestamp - previousTimestamp;
NSLog(@"diff time %f", timeSincePrevious);
}
请检查这一点,我也比较触动,但它越变越慢http://stackoverflow.com/questions/21952274/how-多点触控顺序 – Ranjit 2014-02-24 12:38:45
请编辑有关上下方向的注释,它们相反 – Garnik 2014-11-03 21:29:01