Skip to content

Commit

Permalink
新增支持设置侧滑返回手势block回调
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyouPrince committed Feb 23, 2024
1 parent 8315d72 commit 3bb78af
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion XYNav/XYNav/Classes/XYNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class XYNavigationController: UINavigationController {
// MARK: - public vars
var panGesture: UIPanGestureRecognizer?
private var tempViewControllers: [UIViewController] = []
public typealias PanGesturePopCallback = (_ popedViewController: UIViewController)->()
private static var panGestureEndCallbacks: [PanGesturePopCallback] = []

// MARK: - life circle
public override func viewDidLoad() {
Expand Down Expand Up @@ -271,6 +273,12 @@ extension XYNavigationController {
setDefaultBarColor(navBarTintColor)
}
}
/// 添加全局侧滑返回手势结束的监听
/// - Parameter barColor: 导航栏本身颜色
/// - Note: 此属性设置之后会影响导航栏透明效果, 导航栏会变味不透明
@objc static public func addPanGestureEndCallback(callback: @escaping PanGesturePopCallback) {
panGestureEndCallbacks.append(callback)
}

}

Expand Down Expand Up @@ -312,7 +320,8 @@ extension XYNavigationController: UINavigationControllerDelegate {
let afterControllers = self.viewControllers
if beforeControllers.count > afterControllers.count, let poped = beforeControllers.last { // pop last
DispatchQueue.main.async {
NotificationCenter.default.post(name: NSNotification.Name("XYNavGesturePopNotification"), object: poped)
NotificationCenter.default.post(name: NSNotification.Name.XYNavGesturePopNotification, object: poped)
XYNavigationController.panGestureEndCallbacks.forEach({$0(poped)})
}
}
})
Expand All @@ -321,3 +330,7 @@ extension XYNavigationController: UINavigationControllerDelegate {
}
}
}

extension NSNotification.Name {
public static let XYNavGesturePopNotification = NSNotification.Name("XYNavGesturePopNotification")
}

0 comments on commit 3bb78af

Please sign in to comment.