开发者

swipe distance in iphone sdk?

开发者 https://www.devze.com 2023-02-03 04:25 出处:网络
Through swipe gesture, is it possible to cal开发者_开发知识库culate the distance of swipe (up, down, left, right)?- (CGFloat)distanceBetweenTwoPoints:(CGPoint)fromPoint toPoint:(CGPoint)toPoint

Through swipe gesture, is it possible to cal开发者_开发知识库culate the distance of swipe (up, down, left, right)?


- (CGFloat)distanceBetweenTwoPoints:(CGPoint)fromPoint toPoint:(CGPoint)toPoint

{
float x = toPoint.x - fromPoint.x;
float y = toPoint.y - fromPoint.y;
return sqrt(x * x + y * y);
}

Hope its help you, just pass starting and endpoint to this method ....


I've used an approach similar to this article to recognise swipe gestures of a certain number of pixels, but if you're using a base SDK of at least 4 try using UISwipeGestureRecognizer which can make it much easier; see this post.

0

精彩评论

暂无评论...
验证码 换一张
取 消