ios - 如何使用 swiftUI 更改键盘以反映段选择的输入类型?
问题描述
目前,我可以使用与 SwiftUI 视图上的字母数字或数字键盘输入类型相对应的分段选择器来关闭并显示键盘。我想知道如何在不被解雇和代表的情况下更换键盘。因此,当点击切换时,键盘会自动调整。我正在努力使 UI 更简单,因为它需要用户额外点击,所以存在一个小的不便。
public struct ContentView: View {
@State private var selectedInputType: Int = 0
@State private var keyboardType: KeyboardInputType = .name
@State private var selectedKeyboardType: KeyboardInputType = .name
@State private var inputTypes: KeyboardInputType.AllCases = KeyboardInputType.allCases
public var body: some View {
Picker(selection: $selectedKeyboardType, label: Text("SomeInputHere")) {
ForEach(0..<KeyboardInputType.allCases.count) { type in
Text(self.inputTypes[type].description).tag(type)
}
}.pickerStyle(SegmentedPickerStyle())
.onReceive([self.selectedInputType].publisher.first(), perform: { (value) in
DispatchQueue.main.async {
self.keyboardType = KeyboardInputType(rawValue: value)!
}
print(self.selectedInputType)
})
}
}
解决方案
推荐阅读
- c# - Xamarin Forms ListView ScrollTo 一个空组
- python - 如何从 Python 3.7 docker 映像运行 SSL_library_init()
- jfreechart - jfreechart折线图曲线不打开拐点
- javascript - ga() 函数 Google Analytics 在 Google Tag Manager 中实现为标签
- javascript - 如何从nodejs中的另一个函数获得响应
- python - 你能解决我的“websockets AttributeError”问题吗
- c# - 承载错误 - invalid_token - 未找到签名密钥
- odata - How to answer OData sample questions
- c# - 订票系统:比较两个字符串
- neutralinojs - 有一种方法可以从 NeutralinoJS 获取一个 exe/linux 二进制/应用文件吗?