UIKitTabView Gist 该要点将UIKit选项卡视图集成到SwiftUI,以便在切换选项卡并且双击选项卡时都不会重置导航堆栈的情况下,回到选项卡中的根视图。
它不支持双击选项卡以滚动到顶部,例如IG / FB / Twitter。
Tap tab bar to scroll to top of UITableViewController 我在Swift中找到了几种解决方案,上面是一个示例。但是我无法在SwiftUI上使用它,我猜这是语法上的区别。
我正在测试以下内容(将列表添加到Gist中的原始示例中)
struct ExampleView: View {
@State var text: String = ""
var body: some View {
UIKitTabView([
UIKitTabView.Tab(view: NavView(), title: "ImTab1", image: "heart"),
UIKitTabView.Tab(view: Text("Second View"), title: "ImTab2", image: "person")
])
}
}
struct NavView: View {
@State var yOffset: CGFloat = 0
var body: some View {
NavigationView {
ScrollView {
ForEach(0..<100) { i in
Text("Hello \(i)")
}
NavigationLink(destination: Text("This page stays when you switch back and forth between tabs (as expected on iOS)")) {
Text("Go to detail")
}
}
}
}
}