iOS:ScrollToRowatineXpath无法正确滚动…因为插入?
我终于找到了我的方法,当显示键盘时,我的表格视图向上移动。iOS:ScrollToRowatineXpath无法正确滚动…因为插入?,ios,objective-c,uitableview,uiscrollview,Ios,Objective C,Uitableview,Uiscrollview,我终于找到了我的方法,当显示键盘时,我的表格视图向上移动。我的所有单元格都包含一个文本字段和一些标签。到目前为止,原始方法(奇怪的是,这个方法也是…)只滚动到文本字段可见的范围,而不是整个单元格 但是为什么呢?我要把整个牢房都卷起来。我是不是计算错了插图?但我不这么认为……我所有的视图都有一个表视图和一个页脚视图(高度55)。有些在桌子上方也有一个收割台(高度80)。但在这两种情况下,都不会将整个单元格滚动到视图中,只有文本字段。 atScrollPosition参数的影响为零,且其滚动始终相同
我的所有单元格都包含一个文本字段和一些标签。到目前为止,原始方法(奇怪的是,这个方法也是…)只滚动到文本字段可见的范围,而不是整个单元格 但是为什么呢?我要把整个牢房都卷起来。我是不是计算错了插图?但我不这么认为……我所有的视图都有一个表视图和一个页脚视图(高度55)。有些在桌子上方也有一个收割台(高度80)。但在这两种情况下,都不会将整个单元格滚动到视图中,只有文本字段。
atScrollPosition参数的影响为零,且其滚动始终相同
- (void)keyboardWasShown:(NSNotification*)aNotification
{
//All table views are embedded in the parent view
//The parent view y is defined by the status and navigation bar, the height by the tab bar
CGRect viewRect = self.view.frame;
CGRect tableRect = self.tableView.frame;
//The keyboard size will be adjusted that the height is really only the height overlapping the table
NSDictionary* info = [aNotification userInfo];
CGSize kbOriginalSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
CGFloat effectiveKeyBoardHeight = kbOriginalSize.height - TABBARHEIGHT - (viewRect.size.height - tableRect.size.height - tableRect.origin.y); //the last origin property is important to find out if there is a header
if(effectiveKeyBoardHeight < 0) effectiveKeyBoardHeight = 0;
CGSize kbSize = CGSizeMake(kbOriginalSize.width, effectiveKeyBoardHeight);
//Now the content insets will be adjusted for the calculated part of the keyboard overlapping the table
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
self.tableView.contentInset = contentInsets;
self.tableView.scrollIndicatorInsets = contentInsets;
// If active text field is hidden by keyboard, scroll it so it's visible
// I've changed the apple code here! They use viewRect..in my app this doesn't make any sense, tableRect is key
tableRect.size.height -= kbSize.height;
if (!CGRectContainsPoint(tableRect, self.activeField.frame.origin) ) {
//[self.tableView scrollRectToVisible:cell.frame animated:YES];
[self.tableView scrollToRowAtIndexPath:[self indexPathForCellContainingUIElement:self.activeField] atScrollPosition:UITableViewScrollPositionNone animated:YES];
}
}
-(无效)键盘显示:(NSNotification*)提示
{
//所有表视图都嵌入到父视图中
//父视图y由状态和导航栏定义,高度由选项卡栏定义
CGRect viewRect=self.view.frame;
CGRect tableRect=self.tableView.frame;
//将调整键盘大小,使其高度实际上只是与桌子重叠的高度
NSDictionary*info=[aNotification userInfo];
CGSize kbOriginalSize=[[info-objectForKey:UIKeyboardFrameBeginUserInfo]CGRectValue].size;
CGFloat effectiveKeyBoardHeight=kbOriginalSize.height-TABBARHEIGHT-(viewRect.size.height-tableRect.size.height-tableRect.origin.y);//最后一个origin属性对于确定是否有标头很重要
如果(有效键盘高度<0)有效键盘高度=0;
CGSize kbSize=CGSizeMake(kbOriginalSize.width,effectiveKeyBoardHeight);
//现在,内容插入将针对键盘与表格重叠的计算部分进行调整
UIEdgeInsets contentInsets=UIEdgeInsetsMake(0.0,0.0,kbSize.height,0.0);
self.tableView.contentInset=contentInsets;
self.tableView.ScrollIndicationSets=内容插入集;
//如果活动文本字段被键盘隐藏,请滚动它使其可见
//我在这里更改了苹果的代码!他们使用viewRect。在我的应用程序中,这没有任何意义,tableRect是关键
tableRect.size.height-=kbSize.height;
if(!CGRectContainsPoint(tableRect,self.activeField.frame.origin)){
//[self.tableView scrollRectToVisible:cell.frame动画:是];
[self.tableView ScrollToRowatineXpath:[self-IndexPathForcellContainingField:self.activeField]在ScrollPosition:UITableViewScrollPositionNone动画:是];
}
}
您检查过单元格的边框了吗?是的,单元格的边框看起来不错……我是说宽度、高度等。我也尝试过[self.tableView scrollRectToVisible:cell.frame]。同样的结果。当我将contentInset再调整30像素时,一切似乎都正常,但我不明白为什么。没有这些额外的30像素,我的桌子足够大了,所有的东西都计算正确了。你找到解决办法了吗?