Kaynağa Gözat

1.修改公共方法

wenweiwei 3 yıl önce
ebeveyn
işleme
b1bcd727d9

+ 32 - 2
BFCommonKit/Classes/BFBase/Controller/PQBaseViewController.swift

@@ -190,8 +190,11 @@ open class PQBaseViewController: UIViewController, UIGestureRecognizerDelegate {
     /// 拦截侧滑手势
     /// - Returns: <#description#>
     @objc private func popGesture(panGes: UIPanGestureRecognizer) {
-        if panGes.state == .ended, popGestureHandle != nil {
-            popGestureHandle!()
+        if panGes.state == .ended {
+            let translation = panGes.translation(in: view)
+            if popGestureHandle != nil, translationDric(translation: translation) == .moveDirectionRight, translation.x > 60 {
+                popGestureHandle!()
+            }
         }
     }
 
@@ -201,4 +204,31 @@ open class PQBaseViewController: UIViewController, UIGestureRecognizerDelegate {
         }
         return true
     }
+
+    /// 判断滑动方向
+    /// - Parameter translation: <#translation description#>
+    /// - Returns: <#description#>
+    func translationDric(translation: CGPoint) -> moveDirection {
+        let absX = abs(translation.x)
+        let absY = abs(translation.y)
+        // 设置滑动有效距离
+        if max(absX, absY) < 10 {
+            return .moveDirectionNormal
+        }
+        if absX > absY {
+            if translation.x < 0 {
+                return .moveDirectionLeft
+            } else {
+                return .moveDirectionRight
+            }
+
+        } else if absY > absX {
+            if translation.y < 0 {
+                return .moveDirectionUp
+            } else {
+                return .moveDirectionDown
+            }
+        }
+        return .moveDirectionNormal
+    }
 }