Skip to content

Instantly share code, notes, and snippets.

@hhhello0507
Created March 25, 2025 13:20
Show Gist options
  • Save hhhello0507/e09b88827753caf1e6bb7569452b3564 to your computer and use it in GitHub Desktop.
Save hhhello0507/e09b88827753caf1e6bb7569452b3564 to your computer and use it in GitHub Desktop.
//
// UINavigationControllerExt.swift
// DodamDodam
//
// Created by hhhello0507 on 7/28/24.
//
import UIKit
extension UINavigationController: UIKit.UIGestureRecognizerDelegate {
override open func viewDidLoad() {
super.viewDidLoad()
navigationBar.isHidden = true
interactivePopGestureRecognizer?.isEnabled = false
let popGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:)))
popGestureRecognizer.delegate = self
view.addGestureRecognizer(popGestureRecognizer)
}
public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
viewControllers.count > 1
}
@objc private func handlePanGesture(_ gesture: UIPanGestureRecognizer) {
if let interactivePopGesture = interactivePopGestureRecognizer,
let targets = interactivePopGesture.value(forKey: "targets") as? [NSObject],
let targetObject = targets.first,
let target = targetObject.value(forKey: "target") as? AnyObject {
let selector = NSSelectorFromString("handleNavigationTransition:")
_ = target.perform(selector, with: gesture)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment