我正在使用 DatePickerDialog 库在单击时间文本字段时获取日期选择器。但是,当我单击时间文本字段上方的 Trainer-2 文本字段时,键盘会出现,这很好,但是当我单击时间文本字段时,键盘不会消失,并且日期选择器会出现在其后面,因此页面会卡住。
下面是代码。
func textFieldDidBeginEditing(_ textField: UITextField) {
if textField == timeTextField {
self.view.endEditing(true)
self.getTime(textField: textField)
}
}
func getTime(textField: UITextField) {
DispatchQueue.main.async {
DatePickerDialog().show(title: "DatePicker", doneButtonTitle: "Done", cancelButtonTitle: "Cancel", datePickerMode: .time) {
(time) -> Void in
guard let date_time = time else { return }
}
}
下面是图片。
1)当单击 Trainer-1 文本字段时,会出现键盘,这很好。
2)当点击时间文本字段时获取日期选择器
我只是希望当单击时间文本字段以获取 DatePicker 时键盘消失。
谢谢。
最佳答案
你可以尝试如下..
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
//print("While entering the characters this method gets called")
if(textField == timeTextField){
return false;
}
return true;
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
关于ios - 单击文本字段以从 DatePickerDialog 获取日期时键盘卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46560800/