交互式弹出手势识别器应允许用户在滑过屏幕的一半以上(或这些行周围的内容)时返回导航堆栈中的上一个视图。在SwiftUI中,如果滑动距离不够远,手势不会被取消。
SwiftUI: https ://imgur.com/xxVnhY7
UIKit: https ://imgur.com/f6WBUne
题:
使用SwiftUI视图时能否获得UIKit行为?
尝试次数
我试图将UIHostingController嵌入UINavigationController内,但其行为与NavigationView完全相同。
struct ContentView: View {
var body: some View {
UIKitNavigationView {
VStack {
NavigationLink(destination: Text("Detail")) {
Text("SwiftUI")
}
}.navigationBarTitle("SwiftUI", displayMode: .inline)
}.edgesIgnoringSafeArea(.top)
}
}
struct UIKitNavigationView<Content: View>: UIViewControllerRepresentable {
var content: () -> Content
init(@ViewBuilder content: @escaping () -> Content) {
self.content = content
}
func makeUIViewController(context: Context) -> UINavigationController {
let host = UIHostingController(rootView: content())
let nvc = UINavigationController(rootViewController: host)
return nvc
}
func updateUIViewController(_ uiViewController: UINavigationController, …Run Code Online (Sandbox Code Playgroud)