Created
September 18, 2018 13:34
-
-
Save JayachandraA/78a94b1b4359026c59a0a037e362488d to your computer and use it in GitHub Desktop.
How to handle the keyboard show and hide animation in iOS
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
NotificationCenter.default.addObserver(self, selector: #selector(self.handleKeyboard), name: .UIKeyboardWillHide, object: nil) | |
NotificationCenter.default.addObserver(self, selector: #selector(self.handleKeyboard), name: .UIKeyboardWillShow, object: nil) |
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
func handleKeyboard(_ aNotification: Notification?) { | |
let info = aNotification?.userInfo | |
let value = info?[UIKeyboardAnimationDurationUserInfoKey] as? NSValue | |
var duration: TimeInterval = 0 | |
value?.getValue(&duration) | |
if aNotification?.name == .UIKeyboardWillHide { | |
//* KEYBOARD HIDE * | |
//calculate your view frames and handle UI changes | |
/* | |
. | |
. | |
. | |
. | |
. | |
*/ | |
moveCustomView(false, duration: duration) | |
} | |
if aNotification?.name == .UIKeyboardWillShow { | |
//* KEYBOARD SHOW * | |
//calculate your view frames and handle UI changes | |
/* | |
. | |
. | |
. | |
. | |
. | |
*/ | |
moveCustomView(true, duration: duration) | |
} | |
} | |
func moveCustomView(_ move: Bool, duration time: TimeInterval) { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment