Ios 仅当键盘覆盖视图时,如何更改UITableView内容插入?

Ios 仅当键盘覆盖视图时,如何更改UITableView内容插入?,ios,uitableview,Ios,Uitableview,我有一个包含tableview的视图控制器。我在我的应用程序中的多个地方重复使用了这个视图控制器,因此它位于拆分视图控制器内,也位于iPad上的popover内 我添加了观察者来监听键盘显示/隐藏,并根据键盘高度更改内容插入。每当视图控制器达到全屏高度时,它就可以工作,但在popover中不起作用,popover会调整大小,而tableview实际上没有被键盘覆盖,给我留下一堆空白 有解决办法吗?如果键盘覆盖了视图,我如何才能更改内容插图?您只需要找到键盘将覆盖多少表视图,然后将插图设置为该值

我有一个包含tableview的视图控制器。我在我的应用程序中的多个地方重复使用了这个视图控制器,因此它位于拆分视图控制器内,也位于iPad上的popover内

我添加了观察者来监听键盘显示/隐藏,并根据键盘高度更改内容插入。每当视图控制器达到全屏高度时,它就可以工作,但在popover中不起作用,popover会调整大小,而tableview实际上没有被键盘覆盖,给我留下一堆空白


有解决办法吗?如果键盘覆盖了视图,我如何才能更改内容插图?

您只需要找到键盘将覆盖多少表视图,然后将插图设置为该值

/* Get the keyboard rect (which is screen coordinates) in tableView coordinates */
CGRect endFrameScreen = [[note.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect endFrameWindow = [tableView.window convertRect:endFrameScreen fromWindow:nil];
CGRect endFrameView = [tableView convertRect:endFrameWindow fromView:nil];

if (!CGRectIntersectsRect(tableView.bounds, endFrameView))
{
    /* The keyboard will not cover our tableView; nothing to do */
    return;
}

/* This is how much we need to inset */
CGFloat bottomInset = CGRectGetMaxY(tableView.bounds) - endFrameView.origin.y;
如果仅使用iOS8+,则可以使用convertRect:fromCoordinateSpace:[[UIScreen mainScreen]coordinateSpace]将两个convertRect步骤更改为单个步骤