2016-10-01 76 views

回答

0

手势识别器本身未检测到距离。

相反,您将使用手势识别器移动视图,然后在手势结束时决定视图是否移动超过某个点,然后采取相应措施。

因此,在一个简单的例子中,您可以测试视图是否已经移动了一半以上的屏幕:如果是这样,您继续移动它并继续到另一个视图;如果不是,则设置一个动画使视图回到起点。

希望有帮助。

您可能想查看:
https://www.raywenderlich.com/62435/make-swipeable-table-view-cell-actions-without-going-nuts-scroll-views这更加深入地解释了这种方法。

0

我用这FUNC两点之间计算距离:

//Distance 
extension CGPoint { 
    func distanceCount(_ point: CGPoint) -> CGFloat { 
     return abs(CGFloat(hypotf(Float(point.x - x), Float(point.y - y)))) 
    } 
} 

用法:

let myDistance = p1.distanceCount(p2) //p1 is firstTouch and p2 is when user stops touching. 

然后你就可以像

if distance < SomeValue { 
    //Some code 
} 

希望它会帮助你一点点。