1
所以我展示上,当键盘出现,然后隐藏它,当键盘被解雇,但动画的流量是不够光滑顺利隐藏和显示一个按钮,按键盘上的可用性
我的键盘顶部的按钮i要它来上下键盘(不阻塞UI)
图片:
WHEN键盘出现时,你可以看到,键盘仍然不FULLLY出现但我的按钮,这里
当它隐藏,还没有完全撤职,但按钮消失
我的代码:
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
}
}
需要一个时间间隔嗨,哥们其工作正常,但有什么用'UIKeyboardAnimationDurationUserInfoKey'? –
你得到确切的timeInterval键盘外观(通常为0.25) – Igor
动画,但如何从'UIKeyboardAnimationDurationUserInfoKey'获取它?它的字符串是正确的? '让公共让UIKeyboardAnimationDurationUserInfoKey:字符串// NSNumber双# –