@FocusState 用于管理视图中的焦点状态,通常与表单和文本输入相关联。
struct FocusExampleView: View {
@State private var name = ""
@FocusState private var isNameFieldFocused: Bool
var body: some View {
TextField("Name", text: $name)
.focused($isNameFieldFocused)
Button("Submit") {
isNameFieldFocused = false
}
}
}