Skip to content

Instantly share code, notes, and snippets.

@kopyl
Created January 11, 2026 18:37
Show Gist options
  • Select an option

  • Save kopyl/78600e5a9e0865dac02fdbd7d845139b to your computer and use it in GitHub Desktop.

Select an option

Save kopyl/78600e5a9e0865dac02fdbd7d845139b to your computer and use it in GitHub Desktop.
"targets" approach
import UIKit
class SwipeNavigationController: UINavigationController, UIGestureRecognizerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
setupFullScreenSwipeBack()
}
private func setupFullScreenSwipeBack() {
guard let interactivePopGestureRecognizer = interactivePopGestureRecognizer,
let targets = interactivePopGestureRecognizer.value(forKey: "targets") as? [AnyObject] else { return }
let panGesture = UIPanGestureRecognizer()
panGesture.setValue(targets, forKey: "targets")
panGesture.delegate = self
view.addGestureRecognizer(panGesture)
/// Disable the default edge-only gesture
interactivePopGestureRecognizer.isEnabled = false
}
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
guard viewControllers.count > 1 else { return false }
if let panGesture = gestureRecognizer as? UIPanGestureRecognizer {
let velocity = panGesture.velocity(in: view)
/// Only trigger on horizontal swipe to right
let isHorizonralSwipeToRight = velocity.x > 0 && abs(velocity.x) > abs(velocity.y)
if isHorizonralSwipeToRight {
if viewControllers.last is SleepRecordDetailsViewController &&
TransitionManager.shared.appHasUnsavedRecordChanges {
TransitionManager.shared.goFromRecordDetailsToMain()
return false
}
}
return isHorizonralSwipeToRight
}
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment