我有以下代码可用于IOS 10,但现在它在IOS 11 beta上运行时不再起作用.
if let userInfo = notification.userInfo {
if let keyboardSize = (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
print(keyboardSize)
}
}
Run Code Online (Sandbox Code Playgroud)
这是我打印尺寸时得到的:
(0.0, 0.0, 0.0, 0.0)
(0.0, 736.0, 414.0, 0.0)
Run Code Online (Sandbox Code Playgroud)
谁知道为什么这已停止工作?或者,如果我有其他选择来获得键盘尺寸?
Dou*_*mos 15
用UIKeyboardFrameEndUserInfoKey而不是UIKeyboardFrameBeginUserInfoKey
因此,将代码更改为以下内容将解决您的问题:
if let userInfo = notification.userInfo {
if let keyboardSize = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
print(keyboardSize)
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3396 次 |
| 最近记录: |