当我NavigationView
在TabView
.
这是我的代码,
struct MainView: View {
@State private var selectedTab: Int = 0
var body: some View {
TabView(selection: $selectedTab) {
NavigationView {
ScrollView {
VStack {
ForEach(0..<30) { i in
Text("Hello World")
.padding()
.frame(minWidth: .zero, maxWidth: .infinity)
}
}
}.background(Color.red)
.navigationTitle("Home View")
}.background(Color.green)
.navigationViewStyle(StackNavigationViewStyle())
.tabItem {
TabItem(title: "Explore", systemImage: selectedTab == 0 ? "house.fill" : "house")
}.tag(1)
ExploreView()
.background(Color.red)
.tabItem {
TabItem(title: "Explore", systemImage: selectedTab == 1 ? "safari.fill" : "safari")
}.tag(1)
}
}
}
这是我的场景委托代码,
struct RootView: View {
var body: some View {
MainView()
}
}
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo _: UISceneSession, options _: UIScene.ConnectionOptions) {
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
self.window = window
}
let host = UIHostingController(rootView: RootView())
window?.rootViewController = host
window?.makeKeyAndVisible()
}
}
ScrollView
(位于 内)的高度NavigationView
没有占据整个屏幕。我尝试了所有技巧(填充,框架,GeometryReader
...),但没有运气。我无法弄清楚我在这里做错了什么,任何帮助将不胜感激。