Sav*_*les 11 keyboard ios swift
我用了 :
NotificationCenter.default.addObserver(self, selector:#selector(keyboardWillShow), name: .UIKeyboardWillShow, object: nil)
@objc func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
let keyboardHeight : Int = Int(keyboardSize.height)
print("keyboardHeight",keyboardHeight)
KeyboardHeightVar = keyboardHeight
}
}
Run Code Online (Sandbox Code Playgroud)
进行更改以获取键盘的高度,但高度不包括建议栏。如何获得键盘高度加上建议栏高度的值?
使用UIKeyboardFrameEndUserInfoKey
而不是UIKeyboardFrameBeginUserInfoKey
返回正确的键盘高度。例如,如果键盘没有工具栏,则返回 216.0 高度。使用工具栏 - 260.0
使用UIKeyboardFrameEndUserInfoKey
代替UIKeyboardFrameBeginUserInfoKey
和UIKeyboardDidShow
代替UIKeyboardWillShow
。
NotificationCenter.default.addObserver(self, selector:
#selector(keyboardWillShow), name: .UIKeyboardDidShow, object: nil)
@objc func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
let keyboardHeight : Int = Int(keyboardSize.height)
print("keyboardHeight",keyboardHeight)
KeyboardHeightVar = keyboardHeight
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3156 次 |
最近记录: |