在下面的代码中,ContentView
的背景色在两秒钟后不变.
struct ContentView: View {
@State private var bool: Bool = false
var body: some View {
NavigationStack(root: {
Group(content: {
if bool {
Color.red
} else {
Color.blue
}
})
.onAppear(perform: {
DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
print(">>>")
bool = true
})
})
})
}
}
然而,当用NavigationView(content: {
替换NavigationStack(root: {
时,问题消失了.
是有人面临同样的问题,还是我做错了什么?我使用的是XCode 14.0 beta 2 (14A5229c)
,在iOS 16.0 (20A5303i).
上运行它,这个问题在模拟器和物理设备上都会发生.