In Swiftui, when I jump from a page containing Navigationbar to a hidden page in Navigationbar, then swipe back, and then click on the jump button, the page will freeze and not respond.I used Iphone14 promax ,ios17.2.1,Tested normal on iOS 16 Here is my test code
struct TestVew : View {
var body: some View {
NavigationView {
ZStack{
NavigationLink {
SecondView()
} label: {
Text("To SecondView")
}
}
.navigationTitle("First page")
}
}
}
struct SecondView : View {
var body: some View {
VStack{
Text("SecondView")
}
.navigationBarHidden(true)
}
}
extension UINavigationController: UIGestureRecognizerDelegate {
override open func viewDidLoad() {
super.viewDidLoad()
interactivePopGestureRecognizer?.delegate = self
}
public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
return viewControllers.count > 1
}
}
I hope that when I click on NavigationLink again, it can jump to the page normally and return with normal gestures. Repeating the entire action should not get stuck
The issue seems to be caused by using navigationTitle and navigationBarHidden(true) together. Commenting one of them makes the code run as it should. Why? That's anyone's guess. Now, I have solution for having the swipe gesture work and do any customisation (iOS 15+ compatible) you want to your header:
I know it's a lot of code, but with this you can make any view have the swipe to go back gesture. You use it like this:
Also, as I said, if you want a custo navigation you can check my other answer here Custom Navbar. Let me know if that worked for you!