当我们在UIScrollView中用两个手指做多点触摸时,我们得到两个CG点。我想找到他们之间的距离。然后再次我们做捏(内部或外部),然后我们将再次得到两点。然后,在找到这两个点之间的距离后,我想决定我是否捏住了。如果我已经挤进,肯定新的距离会更小,反之亦然。
When we do multitouch with two fingers in a UIScrollView, we get two CG points. I want to find the distance between them. Then when again we do the pinch(inside or outside), Then we will again get two points. Then after finding the distance again between these two points , I want to decide whether I pinched in or out. If i have pinched in, surely the new distance will be lesser and vice versa.
但不知道如何找到2点之间的距离的精确测量做比较?
But don't know how to find an accurate measurement for the distance between 2 points for doing comparison ? Is anyone having idea about this ?
推荐答案p1 code> p2 :
Distance between p1 and p2:
CGFloat xDist = (p2.x - p1.x); CGFloat yDist = (p2.y - p1.y); CGFloat distance = sqrt((xDist * xDist) + (yDist * yDist));背景:勾股定理
编辑:如果您只需要计算点之间的距离是增加还是减少, sqrt(),这将使它更快一点。
if you only need to calculate if the distance between the points increases or decreases, you can omit the sqrt() which will make it a little faster.
更多推荐
如何找到两个CG点之间的距离?
发布评论