SwiftUI ColorPicker 导致弹出到根视图
SwiftUI ColorPicker cause pop to root view
我有这个奇怪的问题。当我单击 ColorPicker 时,视图消失并返回到根视图。我在下面附上了屏幕记录。有人知道如何解决这个问题吗?
模拟器上的代码运行 ios 15.2
See screen record here
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
TabView {
HomePageView()
.tabItem {
Label("Home", systemImage: "circle.grid.cross.fill")
}
ProfileView()
.tabItem {
Label("Profile", systemImage: "person.fill")
}
}
.background(.secondary)
}
}
}
struct HomePageView: View {
var body: some View {
Text("Home View")
}
}
struct ProfileView: View {
var body: some View {
NavigationLink {
ColorPickerView()
} label: {
Text("Color Picker View")
}
}
}
struct ColorPickerView: View {
@State var bgColor = Color.blue
var body: some View {
ColorPicker("Pick color", selection: self.$bgColor)
.padding(.horizontal, 15)
}
}
NavigationView
在每个选项卡中而不是在 TabView
之外
我有这个奇怪的问题。当我单击 ColorPicker 时,视图消失并返回到根视图。我在下面附上了屏幕记录。有人知道如何解决这个问题吗?
模拟器上的代码运行 ios 15.2
See screen record here
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
TabView {
HomePageView()
.tabItem {
Label("Home", systemImage: "circle.grid.cross.fill")
}
ProfileView()
.tabItem {
Label("Profile", systemImage: "person.fill")
}
}
.background(.secondary)
}
}
}
struct HomePageView: View {
var body: some View {
Text("Home View")
}
}
struct ProfileView: View {
var body: some View {
NavigationLink {
ColorPickerView()
} label: {
Text("Color Picker View")
}
}
}
struct ColorPickerView: View {
@State var bgColor = Color.blue
var body: some View {
ColorPicker("Pick color", selection: self.$bgColor)
.padding(.horizontal, 15)
}
}
NavigationView
在每个选项卡中而不是在 TabView