so i'm showing a button on top of my keyboard when keyboard is appearing and then hiding it when keyboard dismissed but the flow of animation is not smooth enough
i want to it come up and down with keyboard (without blocking the UI)
images:
WHEN KEYBOARD APPEARS , YOU CAN SEE THAT KEYBOARD IS STILL NOT FULLLY APPEARED BUT MY BUTTON IS HERE
AND WHEN IT HIDES , STILL NOT FULLY DISMISSED BUT BUTTON IS GONE
my code :
CODE:
viewDidLoad ...... {
// here we have notification observers for tracking the states of Keyboard
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(LaunchScreenViewController.keyboardWillShow(_:)), name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(LaunchScreenViewController.keyboardWillHide(_:)), name: UIKeyboardWillHideNotification, object: nil)
}
func keyboardWillShow(notification:NSNotification) { // in this function i'm changing the origin (Y) axis of my button os that it can appear on top of my keyboard
let userInfo:NSDictionary = notification.userInfo!
let keyboardFrame:NSValue = userInfo.valueForKey(UIKeyboardFrameEndUserInfoKey) as! NSValue
let keyboardRectangle = keyboardFrame.CGRectValue()
UIView.animateWithDuration(0.3) {
self.nextButtonConstraint.constant = keyboardRectangle.height
}
}
func keyboardWillHide(notification:NSNotification) {
UIView.animateWithDuration(0.5) {
self.nextButtonConstraint.constant = -50 // here i'm making my button out of screen bounds
}
}