enum PanDirection {
case unknown
case horizontal
case vertical
}
// 最小移動距離
private let leastDistance: Float = 15
/// 确定滑動方向
func determinePanDirection(touchPoint: CGPoint,
beginPoint: CGPoint) -> PanDirection {
// 不确定方向,先判斷滑動方向
let dragX = touchPoint.x - beginPoint.x
let dragY = touchPoint.y - beginPoint.y
if fabsf(Float(dragX)) > leastDistance + 30 {
return .horizontal
}
if fabsf(Float(dragY)) > leastDistance {
return .vertical
}
return .unknown
}