我使用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。不知道为什么起源。y来了524 (应该在300附近),高度是44!我也试过了评论线。这两种方式的键盘绑定结果都是44。此问题的只适用于快速键盘。
与this issue相同
发布于 2015-12-19 09:52:41
这个问题在于快速键盘,方法-(void) keyboardWillShow:(NSNotification *)note被调用三次,每次它返回三个不同的原始值和高度时,它第一次给出keyboardBounds = (0,524,320,44),第二次它给出keyboardBounds = (0,308,320,260),最后当它被调用时第三次返回keyboardBounds = (0,271,320,297)。
由于第三方键盘大小不固定..。它们的大小取决于视图的布局方式,因此类似于自动输出(viewDidLoad,viewWillAppear viewWillLayout,viewDidLayout,然后是viewDidAppear,所以在viewDidAppear或viewDidLayout中,视图是在哪里布局的),当视图被完全布局时,它得到了精确的框架。
发布于 2015-12-21 07:08:35
也许您可以尝试其他通知,如:UIKeyboardDidShowNotification、UIKeyboardDidChangeFrameNotification。UIKeyboardWillShowNotification
只要告诉你键盘会显示给你,就不能准确告诉键盘显示的帧。
https://stackoverflow.com/questions/34196856
复制相似问题