Ios 当多次触发时,我的软键盘上的高度会发生变化
我有一个观察到的方法,当显示软键盘时触发。它工作得很好,但由于某种原因,软键盘的高度在隐藏后会发生变化,然后再次显示。我找不到这样做的原因,而且隐藏委托中似乎没有任何更改其值的内容。这是什么原因?我已经解决了这个问题,存储了高度,然后第二次使用它,但是我想知道这个问题的原因Ios 当多次触发时,我的软键盘上的高度会发生变化,ios,objective-c,nsnotificationcenter,iphone-softkeyboard,Ios,Objective C,Nsnotificationcenter,Iphone Softkeyboard,我有一个观察到的方法,当显示软键盘时触发。它工作得很好,但由于某种原因,软键盘的高度在隐藏后会发生变化,然后再次显示。我找不到这样做的原因,而且隐藏委托中似乎没有任何更改其值的内容。这是什么原因?我已经解决了这个问题,存储了高度,然后第二次使用它,但是我想知道这个问题的原因 - (void)keyboardWasShown:(NSNotification*)aNotification { NSDictionary* info = [aNotification userInfo];
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
CGRect visibleRect = self.view.frame;
if (_storedKeyboardHeight.size.height == 0) {
_storedKeyboardHeight.size.height = keyboardSize.height;
}
visibleRect.size.height = _storedKeyboardHeight.size.height;
visibleRect.origin.y = self.view.height - visibleRect.size.height;
CGRect rectOfCellInTableView = [self.loginTableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
//This changes the second time
NSLog(@"The problem is that you are examining the wrong frame:
UIKeyboardFrameBeginUserInfoKey
-显示了voidKeyboard:NSNotification*aNotification
{
NSDictionary*info=[aNotification userInfo];
CGSize keyboardSize=[[info objectForKey:UIKeyboardFrameBeginUserInfo]CGRectValue].size;
CGRect visibleRect=self.view.frame;
如果_storedKeyboardHeight.size.height==0{
_storedKeyboardHeight.size.height=键盘尺寸.height;
}
visibleRect.size.height=_storedKeyboardHeight.size.height;
visibleRect.origin.y=self.view.height-visibleRect.size.height;
CGRect rectOfCellInTableView=[self.loginTableView rectforrowatinexpath:[NSIndexPath indexPathForRow:0第1节]];
//这是第二次改变
NSLog@问题在于您检查的帧错误:
UIKeyboardFrameEndUserInfoKey
显示键盘时,您对显示过程开始时的框架高度不感兴趣。您想知道的是显示过程结束时的框架:
此外,您似乎收到了错误的通知。您尚未显示您注册的通知,但您的方法名称KeyboardWasShow表明您在键盘显示时收到了通知。那太晚了;此通知几乎没有任何意义。您想知道键盘何时打开我会展示。非常好,感谢大家澄清!至于方法名称,我认为它无关紧要,因为它是通过[[NSNotificationCenter defaultCenter]观察到的addObserver:self selector:@SelectoryBoardWasshown:name:UIKeyboardWillShowNotification对象:nil];这只是一个不好的命名;理解,正如我所说,您没有显示您注册的通知,因此我不得不根据名称进行猜测: