@FocusState说明
@FocusState的初始化和@state不太一样
@state
struct ContentView: View {
@State var idString: String
}
ContentView(idString: "123")
@FocusState
@FocusState var isFouced: Bool
VStack {
// ...省略
}
.onAppear {
DispatchQueue.global(qos: .default).async {
isFouced = true
}
// isFouced = true
}
总结
@FocusState需要只能在页面出现后初始化,不像@state可以直接传值进去初始化。