【发布时间】:2020-03-02 14:45:59
【问题描述】:
我有一个观察到的方法,在显示soft keyboard 时触发。它工作正常,但由于某种原因,soft keyboard 的height 在隐藏后会发生变化,然后第二次出现。我找不到原因,并且隐藏委托中似乎没有任何东西可以改变其价值。这是什么原因造成的?我已经通过存储高度然后第二次使用它来解决这个问题,但我想知道这个问题的原因。
- (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(@"???? %f", keyboardSize.height);
//so I store the original value here
NSLog(@"???? %@", CGRectCreateDictionaryRepresentation(_storedKeyboardHeight));
if ((rectOfCellInTableView.origin.y + rectOfCellInTableView.size.height) > visibleRect.origin.y){
CGPoint scrollPoint = CGPointMake(0.0, (rectOfCellInTableView.origin.y + rectOfCellInTableView.size.height) - visibleRect.origin.y + 50);
[self.loginTableView setContentOffset:scrollPoint animated:YES];
}
}
第一次高度是291,第二次是233。
【问题讨论】:
标签: ios objective-c nsnotificationcenter iphone-softkeyboard