2016-10-01 54 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 
} 

希望它會幫助你一點點。