作者:hgo6786689 | 来源:互联网 | 2023-01-26 10:09
我有以下代码可用于IOS 10,但现在它在IOS 11 beta上运行时不再起作用.
if let userInfo = notification.userInfo {
if let keyboardSize = (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
print(keyboardSize)
}
}
这是我打印尺寸时得到的:
(0.0, 0.0, 0.0, 0.0)
(0.0, 736.0, 414.0, 0.0)
谁知道为什么这已停止工作?或者,如果我有其他选择来获得键盘尺寸?
1> Doug Amos..:
用UIKeyboardFrameEndUserInfoKey
而不是UIKeyboardFrameBeginUserInfoKey
因此,将代码更改为以下内容将解决您的问题:
if let userInfo = notification.userInfo {
if let keyboardSize = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
print(keyboardSize)
}
}