我怎样才能获得速度和touchmoved功能手指移动的方向?
我想获得的手指速度和手指的方向,并在UIView类方向的运动和动画的速度应用它。
我读了这个链接,但我不明白的答案,除了它没有解释如何检测的方向:
UITouch运动速度检测
到目前为止,我尝试这样的代码:
-(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);
}