-
-
Save zontan/f4527a1885e24053e748e6cf8ab099dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBOutlet weak var bottomConstraint: NSLayoutConstraint! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
... | |
NotificationCenter.default.addObserver(self, selector: #selector(ChatViewController.keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) | |
NotificationCenter.default.addObserver(self, selector: #selector(ChatViewController.keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) | |
textField.becomeFirstResponder() | |
} | |
@objc func keyboardWillShow(notification: NSNotification) { | |
guard let userInfo = notification.userInfo else { return } | |
guard let keyboardSize = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else { return } | |
let keyboardFrame = keyboardSize.cgRectValue | |
bottomConstraint.constant = 20 + keyboardFrame.height | |
} | |
@objc func keyboardWillHide(notification: NSNotification) { | |
bottomConstraint.constant = 60 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment