swift4.0 确定手势滑动方向

    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
    }

你可能感兴趣的:(swift4.0 确定手势滑动方向)