Hide navigation bar without losing swipe back gesture in SwiftUI

前端 未结 3 1684
野的像风
野的像风 2020-12-09 00:21

In SwiftUI, whenever the navigation bar is hidden, the swipe to go back gesture is disabled as well.

Is there any way to hide the navigation bar while preserving t

3条回答
  •  Happy的楠姐
    2020-12-09 00:27

    When using the UINavigationController extension you might encounter a bug that blocks your navigation after you start swiping the screen and let it go without navigating back. Adding .navigationViewStyle(StackNavigationViewStyle()) to NavigationView does fix this issue.

    If you need different view styles based on device, this extension helps:

    extension View {
        public func currentDeviceNavigationViewStyle() -> AnyView {
            if UIDevice.current.userInterfaceIdiom == .pad {
                return AnyView(self.navigationViewStyle(DefaultNavigationViewStyle()))
            } else {
                return AnyView(self.navigationViewStyle(StackNavigationViewStyle()))
            }
        }
    }
    

提交回复
热议问题