I am using SwiftUI NavigationView to navigate. I cant find how can i disable swipe from the leftmost part of the screen for navigation bar. In tried this way , but it doesn't work for me:
struct DisableSwipeBackGesture: ViewModifier {
func body(content: Content) -> some View {
content
.background(DisableBackSwipeGestureView())
}
}
struct DisableBackSwipeGestureView: UIViewControllerRepresentable {
typealias UIViewControllerType = DisableSwipeBackViewController
func makeUIViewController(context: Context) -> DisableSwipeBackViewController {
DisableSwipeBackViewController()
}
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {}
func makeCoordinator() -> Coordinator {
return Coordinator()
}
class Coordinator: NSObject, UIGestureRecognizerDelegate {
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
return false
}
}
}
final class DisableSwipeBackViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if let navigationController = self.navigationController {
if let interactivePopGestureRecognizer = navigationController.interactivePopGestureRecognizer {
interactivePopGestureRecognizer.delegate = self
interactivePopGestureRecognizer.isEnabled = false
}
}
}
}
extension DisableSwipeBackViewController: UIGestureRecognizerDelegate {
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
return false
}
}
extension View {
func disableSwipeBackGesture() -> some View {
self.modifier(DisableSwipeBackGesture())
}
}
Is there a way to disable this feature?
Post
Replies
Boosts
Views
Activity
In IOS16 its work correctly , but in IOS 17 i see like my navigation bar animate . How can i disable it ?
Text()
.navigationBarBackButtonHidden(true)
.navigationBarHidden(hideNavigationBar)
.animation(nil, value: hideNavigationBar)