-
-
Save zontan/03295131931cab18f490c4a46ae7bff1 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() | |
// Do any additional setup after loading the view. | |
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 = 20 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment