1
我有一個錯誤,當顯示鍵盤和預測文本框在頂部的鍵盤會切換視圖,從而留下黑屏的用戶。發生這種情況的原因是因爲我使用了 - =運算符,這會在每次調用此方法時合併此值。這種方法可以連續調用多次。我試圖找到一種方法來處理這個問題。顯示鍵盤和鍵盤頂部的預測性文本框切換視圖拍攝留下用戶黑屏
func getKeyboardHeight(notification: NSNotification) -> CGFloat {
let userInfo = notification.userInfo
let keyboardSize = userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue
return keyboardSize.CGRectValue().height
}
func keyboardWillShow(notification: NSNotification) {
if bottomTextField.isFirstResponder() {
self.view.frame.origin.y -= getKeyboardHeight(notification)
}
}
func keyboardWillHide(notification: NSNotification) {
if bottomTextField.isFirstResponder() {
self.view.frame.origin.y += getKeyboardHeight(notification)
}
}