I'm making an application in Xcode and would like the button at the bottom of the screen to move according to the keyboard's appearance.
Thank you
When the keyboard is displayed or inhibited, you can listen for notifications to process them. In your view controller, sign up to hear these events as follows:
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShow), name: .UIKeyboardDidShow , object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidHide), name: .UIKeyboardDidHide , object: nil)
}
You should also create the functions you are reporting in selector
:
@objc private func keyboardDidShow() {
// Processe aqui para quando o teclado terminar de ser *exibido*
}
@objc private func keyboardDidHide() {
// Processe aqui para quando o teclado terminar de ser *inibido*
}
There are four such events for the keyboard:
.UIKeyboardWillShow
; .UIKeyboardDidShow
; .UIKeyboardWillHide
; .UIKeyboardDidHide
. You can subscribe to any of them to hear keyboard-related changes.
A more extensive list of events related to your application can be found here .