Я сделал исправление для этой проблемы, комбинируя различные ответы, опубликованные здесь, и немного больше.
override func viewWillAppear(_ animated: Bool) {
// super.viewWillAppear(animated)
}
Комментирование viewWillAppear(animated)
отключает автоматическую c прокрутку UITableViewController.
Теперь в ViewDidLoad () добавлено 2 наблюдателя уведомлений
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
и их функция как
@objc func keyboardWillShow(notification: NSNotification) {
if !isKeyboardShowing {
if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
let keyboardHeight = keyboardSize.height
let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as! NSNumber
let curve = notification.userInfo?[UIResponder.keyboardAnimationCurveUserInfoKey] as! NSNumber
adjustTableViewInsets(keyboardHeight: keyboardHeight, duration: duration, curve: curve)
}
}
}
@objc func keyboardWillHide(notification: NSNotification) {
let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as! NSNumber
let curve = notification.userInfo?[UIResponder.keyboardAnimationCurveUserInfoKey] as! NSNumber
adjustTableViewInsets(keyboardHeight: 0, duration: duration, curve: curve)
}
. Это обеспечит дополнительное пространство для пользователя для прокрутите страницу до конца, даже если клавиатура видна.
Теперь я использовал IQKeyboardManager
для дополнительной функциональности стрелок ВВЕРХ и ВНИЗ, чтобы перейти к следующей UITextField
, и кнопки ГОТОВО, чтобы закрыть клавиатуру.