为什么 UITableVIew 在显示键盘时向下滚动而不是向上滚动?

Why does the UITableVIew scroll down but not up when keyboard is shown?

我有 textViewstableView。当 textViews(朝向 tableView 的底部)被选中时,键盘弹出,并隐藏 textView,您也无法向下滚动。所以我添加了以下代码:

- (void)keyboardWasShown:(NSNotification*)aNotification
{
    NSDictionary* info = [aNotification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
    myTableView.contentInset = contentInsets;
    myTableView.scrollIndicatorInsets = contentInsets;

    CGRect aRect = self.view.frame;
    aRect.size.height -= kbSize.height;
    if (!CGRectContainsPoint(aRect, activeField.frame.origin) ) {
        [self.myTabelView scrollRectToVisible:activeField.frame animated:YES];
    }
}

我现在遇到了相反的问题。当键盘显示时,顶部不显示,也无法一直向上滚动。

你好,你试过使用 TPKeyboardAvoiding 吗?我用它来解决这种情况,而无需编写任何代码……您可以像 CocoaPod 一样快速试用它。