scrollToItemAtIndexPath iOS Swift

scrollToItemAtIndexPath iOS Swift

我希望能够滚动到 header 而不是 header 下的第一项。这很重要的原因是 atScrollPosition 参数设置为 Top,我滚动到特定部分中的第零项。然后这会隐藏 header 并且用户不会收到确认他们已滚动到正确部分的反馈。

有人知道怎么做吗?

而不是 scrollToRowAtIndexPath,使用 scrollRectToVisible。传入一个与table视图大小相同的rect,即可实现精准定位。

因此,如果您希望页眉正好位于顶部,请使用页眉框架,将高度设置为 table 视图的高度,然后将其传递给 scrollRectToVisible

类似于:

CGRect sectionRect = [tableView rectForSection:indexOfSectionToScrollTo];
[tableView scrollRectToVisible:sectionRect animated:YES];

this