解决IOS中UITableViewStylePlain 时对headerview的隐藏
2014-04-22 11:01
639 查看
当设置table的style为UITableViewStylePlain,如果出现viewForHeaderInSection,那么当滑到当前section时这个headerview会在一直stick在tableview的顶部,这也是apple将其命名为header的原因,但有时候我们只需要自定义一个headerview显示一些不方便放到cell里面的view,那么自然而然,我们不想它一直显示在顶部。So how to make it move
off screen when scrolling down?
查了一些资料,解决方案也五花八门:
1. 直接setHidden, 这样只会留下一个空白的区域,高度还是原先的headerview高度;不行
2. 设置tableview的contentoffset 为headerview的高度,然后再贴上headerview,这样做的话也行。只是稍微麻烦点。如下:
3. 将style改成Grouped,这样headerview就不会定在顶部了,但是grouped不好控制,因为每个section之间还是有一段footerview,而且就算将其高度设为0,还是有一小段空白的footer,这样又得重写tableview了,不介意这个高度的话就可以这样解决;
4. 个人目前认为比较好的方法是玩个小小的trick:在stackoverflow上有:http://stackoverflow.com/questions/8949318/scroll-uitableview-header/8949353#8949353
By implementing
section of index
you can instead have the header as the first section that should disappear when it scrolls. In this way, it's not a header for the whole UITableView.
off screen when scrolling down?
查了一些资料,解决方案也五花八门:
1. 直接setHidden, 这样只会留下一个空白的区域,高度还是原先的headerview高度;不行
2. 设置tableview的contentoffset 为headerview的高度,然后再贴上headerview,这样做的话也行。只是稍微麻烦点。如下:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat sectionHeaderHeight = 40;//Change as per your table header hight if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) { scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0); } else if (scrollView.contentOffset.y>=sectionHeaderHeight) { scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0); } }
3. 将style改成Grouped,这样headerview就不会定在顶部了,但是grouped不好控制,因为每个section之间还是有一段footerview,而且就算将其高度设为0,还是有一小段空白的footer,这样又得重写tableview了,不介意这个高度的话就可以这样解决;
4. 个人目前认为比较好的方法是玩个小小的trick:在stackoverflow上有:http://stackoverflow.com/questions/8949318/scroll-uitableview-header/8949353#8949353
By implementing
tableView:viewForHeaderInSection:for
section of index
0,
you can instead have the header as the first section that should disappear when it scrolls. In this way, it's not a header for the whole UITableView.
相关文章推荐
- 使 UITableViewStylePlain Style 的TableView header 不浮动,像Group Style 那样固定,跟随Tableview 滚动,而不会停在顶端。
- iOS Tableview中解决plain样式下,header的浮动问题
- iOS-74-解决UITableViewStyleGrouped 各个section间距调整问题
- tableview 的格式为UITableViewStylePlain,去掉headerview的黏连性
- IOS-UITableViewStyle设置Group、Plain问题
- iOS UITableViewStylePlain 和 UITableViewStyleGrouped的区别
- IOS TableViewStylePlain header 悬停的解决方案
- 【技巧】UITableView 在UITableViewStylePlain模型下,取消headerView的黏结性,不浮动
- IOS-UITableViewStyle设置Group、Plain问题
- 解决UItableView cell的间隔线 separatorStyle ( plain group 两种类型)
- IOS-UITableViewStyle设置Group、Plain问题
- UITableView UITableViewStylePlain模型下 取消headerView的黏结性
- 完美解决!隐藏listview的headerView,实现动态下拉,(仿ios)
- iosiOS开发之UITableView分割线不顶左解决方法
- iOS UITableView-FDTemplateLayoutCell框架 cell重叠 高度返回0.5问题解决
- ios隐藏uitableview下面多余的tableview的线条
- UITableView UITableViewStylePlain UITableViewStyleGrouped
- 去掉UITableViewStylePlain样式下Section停留问题
- iOS6, UITableViewStyleGrouped类型的UITableView 设置背景色无效 解决办法
- IOSUITableView展开隐藏资源