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雙# –