Find the correct keyboard height and assign it to the lower limit of the textView or decrease the y-position of the textView. For instance:
Step 1: make the keyboardHeight property in your viewController.
var keyboardHeight: CGFloat = 0.0
Step-2: Make the @IBOutlet lower bound the textView.
@IBOutlet weak var textViewBottomConstraint: NSLayoutConstraint!
Step 3:
fileprivate func addKeyboardNotification() { NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil) } fileprivate func removeKeyboardNotification() { IQKeyboardManager.shared().isEnabled = true NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillShow, object: nil) NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: nil) }
Copy and paste these functions into your view controllers and call self.addKeyboardNotification() in viewDidLoad() , and you - viewController
Step 4:
deinit { self.removeKeyboardNotification() }
also add this code to your viewController.
Step 5:
func keyboardWillShow(_ notification: Notification) { if let keboardFrame = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue, self.keyboardHeight <= 0.0 { self.keyboardHeight = keboardFrame.height + 45.0 //(Add 45 if your keyboard have toolBar if not then remove it) } UIView.animate(withDuration: 0.3, animations: { self.textViewBottomConstraint.constant = self.keyboardHeight }, completion: { (success) in }) } func keyboardWillHide(_ notification: Notification) { UIView.animate(withDuration: 0.3, animations: { self.textViewBottomConstraint.constant = 0.0 }, completion: { (success) in }) }
So that he controls the textView using the keyboard. If you do not want to use textViewBottomConstraint , you can work with the y-position of textView.