简体   繁体   中英

UITableView Section Header Scrolling

I followed this post to make my section header animate out of view when the tableview is scrolled. However, when scrolling back to the top, the header does not come back into view. Ever. Given that I followed the solution exactly (and I'm not setting the contentInset anywhere else), I'm quite perplexed. Can anyone point me in the right direction? Here is my code:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  CGPoint p = scrollView.contentOffset;

  CGFloat height = [self tableView:self.agendaDetailTable heightForHeaderInSection:0];

  if (p.y <= height && p.y > 0) {
    self.agendaDetailTable.contentInset = UIEdgeInsetsMake(-p.y, 0, 0, 0);
  } else if (p.y >= height) {
    self.agendaDetailTable.contentInset = UIEdgeInsetsMake(-height, 0, 0, 0);
  }
}

为表格启用bouncesalwaysBounceVertical ,以使其在内容的边缘上滚动并在发生这种情况时重写偏移量。

Jacob's solution works well. One issue is that the content is off by one pixel after scroll. I have a header with a black border and can see the problem after I scroll and then return to the top. By changing py > 0 to py >= 0 my header when scrolled back to zero is restored properly.

/* to fix floating headers */
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGPoint p = scrollView.contentOffset;

    CGFloat height = (float) DASHBOARD_SUMMARY_PANEL_HEADER_HEIGHT;

    if (p.y <= height && p.y >= 0) {
        self.SummaryPanelTableView.contentInset = UIEdgeInsetsMake(-p.y, 0, 0, 0);
    } else if (p.y >= height) {
        self.SummaryPanelTableView.contentInset = UIEdgeInsetsMake(-height, 0, 0, 0);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM