【发布时间】:2015-12-22 16:22:59
【问题描述】:
我正在使用UIKeyboardWillShowNotification 和UIKeyboardWillHideNotification 来处理键盘。
这是显示键盘时调用的函数:
-(void) keyboardWillShow:(NSNotification *)note
{
CGRect keyboardBounds;
//[[note.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &keyboardBounds];
NSValue* keyboardFrameBegin = [note.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey];
keyboardBounds = [keyboardFrameBegin CGRectValue];
}
我得到 keyboardBounds = (0, 524, 320, 44) 并且我使用的是 5s。不知道为什么 origin.y 会出现 524(应该在 300 附近)和高度为 44 !
我也尝试过注释行。两种方式的键盘绑定都是 44。此问题仅适用于快速键盘。
同this issue
【问题讨论】:
-
看起来像一个竞争条件。使用
UIKeyboardDidShowNotification时同样的问题? -
收听
UIKeyboardDidChangeFrameNotification并持续保存帧? -
@FabioPoloni 我还没有注册 UIKeyboardDidChangeFrameNotification
-
我仍然认为这是一个竞争条件,所以
UIKeyboardDidChangeFrameNotification可能会给您更多通知,但可能比其他通知更精确。 -
这是在设备上还是模拟器上?您是否有连接到设备的硬件(可能是蓝牙)键盘,或者连接了模拟器的硬件键盘? (硬件 > 键盘 > 连接硬件键盘)
标签: ios iphone swift-keyboard