Я использую IQKeyBoardManager для сборки своего проекта в Swift. У меня проблема в одном указанном c View Controller. Как только я продолжаю спускаться по своим текстовым полям и достигаю текстового поля даты рождения, тогда я хочу, чтобы клавиатура была отклонена. Я попытался добавить функцию, как только значение средства выбора даты было изменено, чтобы закрыть клавиатуру, однако это не сработало. Я хочу, чтобы клавиатура была отклонена, как только мой datePicker активен.
@objc func keyboardDoneClicked() {
switch openedTextFieldTag {
case 1:
firstName.resignFirstResponder()
lastName.becomeFirstResponder()
routing_number.resignFirstResponder()
account_number.resignFirstResponder()
account_holder_name.resignFirstResponder()
case 2:
firstName.resignFirstResponder()
lastName.resignFirstResponder()
routing_number.becomeFirstResponder()
account_number.resignFirstResponder()
account_holder_name.resignFirstResponder()
case 3:
firstName.resignFirstResponder()
lastName.resignFirstResponder()
routing_number.becomeFirstResponder()
account_number.resignFirstResponder()
account_holder_name.resignFirstResponder()
case 4:
firstName.resignFirstResponder()
lastName.resignFirstResponder()
routing_number.resignFirstResponder()
account_number.becomeFirstResponder()
account_holder_name.resignFirstResponder()
case 5:
firstName.resignFirstResponder()
lastName.resignFirstResponder()
routing_number.resignFirstResponder()
account_number.resignFirstResponder()
account_holder_name.resignFirstResponder()
default:
break
}
}
func textFieldDidBeginEditing(_ textField: UITextField) {
openedTextFieldTag = 0
if textField == self.date_of_birth {
view.endEditing(true)
self.datePicker.isHidden = false
self.doneBtn.isHidden = false
self.view.endEditing(true)
date_of_birth.resignFirstResponder()
firstName.resignFirstResponder()
lastName.resignFirstResponder()
routing_number.resignFirstResponder()
account_number.resignFirstResponder()
account_holder_name.resignFirstResponder()
} else {
self.datePicker.isHidden = true
self.doneBtn.isHidden = true
}
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if textField == firstName {
firstName.resignFirstResponder()
lastName.becomeFirstResponder()
routing_number.resignFirstResponder()
account_number.resignFirstResponder()
account_holder_name.resignFirstResponder()
} else if textField == lastName {
firstName.resignFirstResponder()
lastName.resignFirstResponder()
routing_number.becomeFirstResponder()
account_number.resignFirstResponder()
account_holder_name.resignFirstResponder()
} else if textField == routing_number {
firstName.resignFirstResponder()
lastName.resignFirstResponder()
routing_number.becomeFirstResponder()
account_number.resignFirstResponder()
account_holder_name.resignFirstResponder()
} else if textField == account_number {
firstName.resignFirstResponder()
lastName.resignFirstResponder()
routing_number.resignFirstResponder()
account_number.becomeFirstResponder()
account_holder_name.resignFirstResponder()
} else if textField == account_holder_name {
firstName.resignFirstResponder()
lastName.resignFirstResponder()
routing_number.resignFirstResponder()
account_number.resignFirstResponder()
account_holder_name.resignFirstResponder()
date_of_birth.resignFirstResponder()
self.datePicker.isHidden = false
self.doneBtn.isHidden = false
}
return true
}
@objc func pickerEditingDidEnd(_ date: UIDatePicker ) {
print(date)
datePicker.isHidden = true
self.doneBtn.isHidden = true
let formatter = DateFormatter()
formatter.dateFormat = "dd/MM/yyyy"
self.date_of_birth.text = formatter.string(from: self.datePicker.date)
UserDefaults.standard.set(datePicker.date, forKey: "dob")
}
override func viewDidLoad(){
datePicker.date = Date()
datePicker.datePickerMode = .date
datePicker.addTarget(self, action: #selector(pickerEditingDidEnd), for: .editingDidEnd)
datePicker.backgroundColor = UIColor.white
datePicker.layer.borderColor = THEME_BLUE_COLOR.cgColor
datePicker.layer.borderWidth = 1.0
datePicker.isHidden = true
self.view.addSubview(datePicker)
}