我们继续前进。我根据凯文的想法找到了这个方法。为了能够将动画设置为 YES,我使用 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];
}
对于这段代码,当动画设置为YES时,应该在scrollViewDidEndScrollingAnimation和showFirstHeaderLine之间无限循环......它循环,是的,但只有一次......知道为什么吗?