我有一个带有行和部分的UitaiteView。我想滚动到第二部分的第一项,让第一部分的标题可见。就像我手动滚动清单直到达到该状态一样。

---- TOP OF SCREEN ----
Header of first section
Header of the second section
cell 1
cell 2
cell 3
Header of the third section
cell 1
cell 2
...

scrolltorowatIndExpath:[NSINDEXPATH INDEXPATHFORROW:0 INSECTION:1]不执行工作,它隐藏了第一部分的标题。

有帮助吗?

解决方案

我们正在继续。我根据凯文的想法找到了这种方法。为了能够将动画设置为“是”,我使用uiscrollview的委托方法来捕捉动画的结尾。有用。但是,任何有助于不做2个动画的解决方案都将不胜感激。 关于如何做的任何想法吗?

- (IBAction) scrollToToday:(BOOL)animate {
    [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1] atScrollPosition:UITableViewScrollPositionTop animated:animate];
    if (animate == NO) [self showFirstHeaderLine:NO];
}

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
    [self showFirstHeaderLine:YES];
}

- (void) showFirstHeaderLine:(BOOL)animate {
    CGRect headerRect = [self.tableView rectForHeaderInSection:1];
    CGPoint scrollPoint = headerRect.origin;
    scrollPoint.y -= headerRect.size.height;
    [self.tableView setContentOffset:scrollPoint animated:animate];
}

杜德(Dude to the Code),当动画设置为“是”时,该过程应无限地循环scrollviewDidendScrollingAnimation和showfirstheaderline ...它循环,是的,但是只有一次... 有什么想法吗?

其他提示

您可以抓住所需的行的RECT,然后减去上一节的标题高度,然后滚动到该点。如下(未经测试)应该有效:

CGRect rowRect = [table rectForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
CGRect headerRect = [table rectForHeaderInSection:0];
rowRect.origin.y -= headerRect.size.height;
rowRect.size.height += headerRect.size.height;
[table scrollRectToVisible:rowRect animated:YES]; // UITableView is a subclass of UIScrollView

我尝试了您的代码,它可以工作!!

对于循环问题,由于您要设置偏移量(SetContentOffset),因此与滚动无关。它不会致电ScrollView委托。因此,ScrollViewDidendScrollingAnimation将仅调用一次,这是从scrolltorowatindexpath中调用的。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top