我想在弹出窗口出现时使用键盘激活文本字段,与用户点击相同,但在常规视图中工作时,以下代码在弹出窗口中呈现时不起作用。
有什么解决办法吗?谢谢。
struct ContentView: View {
@State var str = ""
@State var show = false
@FocusState private var focused: Bool
var body: some View {
VStack {
Text("Popover")
.onTapGesture {
show.toggle()
}
.popover(isPresented: $show) {
TextField("Popover Textfield", text: $str)
.focused($focused)
.onAppear {
focused = true
}
}
.frame(width: 100, height: 100)
}
}
}
Run Code Online (Sandbox Code Playgroud)