[英]Show header of uitableview on scroll up and hide header of uitableview on scroll down
[英]Show and hide of tableView Header with Scroll?
我想在向下滚动时在tableview的顶部显示视图,而在向上滚动时隐藏。
这是我的努力
tblView.tableHeaderView=headerToolbar;
[tblView setContentOffset:CGPointMake(0, 44) animated:YES];
用户滚动时
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
CGPoint targetPoint = *targetContentOffset;
CGPoint currentPoint = scrollView.contentOffset;
if (targetPoint.y > currentPoint.y) {
[tblView setContentOffset:CGPointMake(0, 0) animated:NO];
}
else {
[tblView setContentOffset:CGPointMake(0, 44) animated:NO];
}
}
但是向上滚动时不起作用。
建议不要将标题视图添加为UITableView顶部的子视图,并带有所需的矩形,而不是标题视图。 当用户向上/向下滚动显示/隐藏时,标题视图将位于表格视图之上。 您可以使用this找到UITableView的滚动方向。
在UITableView的顶部添加一个UIView。 这可以帮助您隐藏和显示视图。
只需对此进行更新。
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
CGPoint targetPoint = *targetContentOffset;
CGPoint currentPoint = scrollView.contentOffset;
if (targetPoint.y > currentPoint.y) {
[self.view insertSubview:theTableView aboveSubview:yourView];
}
else {
[self.view insertSubview:yourView aboveSubview:theTableView];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.