![](/img/trans.png)
[英]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.