Reputation: 90
I am using the following code for text field and text view. It's working properly for text field but the keyboard is still hiding the textview.
@objc func keyboardWillShow(notification: NSNotification) {
guard let info = notification.userInfo, let keyboardFrameValue = info[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue else { return }
let keyboardFrame = keyboardFrameValue.cgRectValue
let keyboardSize = keyboardFrame.size
let contentInsets = UIEdgeInsets(top: 0.0, left: 0.0, bottom: keyboardSize.height + 100, right: 0.0)
tableView.contentInset = contentInsets
tableView.scrollIndicatorInsets = contentInsets
}
@objc func keyboardWillHide(notification: NSNotification) {
let contentInsets : UIEdgeInsets = UIEdgeInsets.init(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0)
self.tableView.contentInset = contentInsets
self.tableView.scrollIndicatorInsets = contentInsets
self.view.endEditing(true)
}
Any help would be appreciated.
Upvotes: 0
Views: 63
Reputation: 357
Please use the library link given below
https://github.com/hackiftekhar/IQKeyboardManager
Upvotes: 1