tableview: 实现tableview 的 section header 跟随tableview滑动
方法一:(只有一个headerView)一段
如果你的tableview恰好只有一个headerView,实现这种效果就好办了。把要设置的headerView设置成tableView的header而不是section = 0的headerView。
self.tableView.tableHeaderView = view;
方法二:
该方法比较简单,设置tableView的style为UITableViewStyleGrouped即可。代码如下
self.tableView = [[UITableView alloc]initWithFrame:[[UIScreen mainScreen]bounds] style:UITableViewStyleGrouped];
当设置成grouped类型之后,头部会出现空白,在每一个section之间也会出现空白,解决方法如下(swift代码):
设置tableHeaderView的高度为一个比较小的值。
let view = UIView.init(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height:0.001))
self.tableView.tableHeaderView = view
设置每一段的段尾值为一个比较小的值,去除空白。
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 0.01
}
方法三:
由于tableView是特殊的scrollView,在controller中加入如下代码:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat sectionHeaderHeight = self.sectionHeight;
// NSLog(@"%f,%f",scrollView.contentOffset.x,scrollView.contentOffset.y);
if(scrollView == self.tableView){
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>= -64) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
} else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}
}
}
其中sectionHeight为你的tableview的section=0的headerView的高度。
由于我的tableViewController是在navigationController中使用的,而使用navigationController会使tableView(scrollView)的subView整体下移64,所以使用scrollView.contentOffset.y>=-64,如果没有使用navigationController就应该使用scrollView.contentOffset.y>=-64。这个根据自己的情况设置就好了。
tableview: 实现tableview 的 section header 跟随tableview滑动的更多相关文章
- iOS 解决tableView中headerView头部视图不跟随tableView滑动的方法
解决方法如下: if (scrollView.contentOffset.y >= 0 && scrollView.contentOffset.y <= pushNewsT ...
- ios开发之--tableview单选/多选实现(非tableview的editing状态)及默认选中
实现思路比较简单,这里仅做记录: 直接上代码: 1,实现didSelectRowAtIndexPath方法 -(void)tableView:(UITableView *)tableView didS ...
- iOS- 如何改变section header
希望这个从UITableViewDelegate协议里得到的方法可以对你有所帮助: - (UIView *) tableView:(UITableView *)tableView viewForHea ...
- 让UITableView的section header view不悬停的方法
当 UITableView 的 style 属性设置为 Plain 时,这个tableview的section header在滚动时会默认悬停在界面顶端.取消这一特性的方法有两种: 将 style 设 ...
- UITableView section header 不固定
iOS系统自带的UITableView,当数据分为多个section的时候,在UITableView滑动的过程中,默认section header是固定在顶部的,滑动到下一个section的时候,下一 ...
- 设置TableView section header的颜色
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInte ...
- 取到 tableview 自定义section header 上的button
在自定义的组头上,添加了一个button,在点击cell是想取到相应的组头上的button来进行操作时(比如说隐藏.是否响应点击事件等)时,我遇到了取不到所有button的问题,试过了常规的通过vie ...
- 【代码笔记】iOS-点击城市中的tableView跳转到旅游景点的tableView,下面会有“显示”更多。
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
- 修改(table的section与上一个section的间距)section header背景颜色
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView * ...
随机推荐
- VMware虚拟机中如何安装VMWare-Tools详解
VMware虚拟机中如何安装VMWare-Tools详解 好处:可以支持图形界面,可以支持共享文件功能等 VMware虚拟机中如何配置显 VMware作为一款虚拟机利器,很多人都利用它来实现Linux ...
- 《wc》-linux命令五分钟系列之十七
本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket. 为了防止某些网站的恶性转载,特在每篇文章前加入此信息,还望读者体谅. ...
- Win8 +PHP+IIS配置
1.安装IIS:控制面板-程序和功能-打开或关闭Windows功能 2.配置PHP环境 -添加ISAPI筛选: -添加脚本映射:
- WF学习笔记(三)
Collection 集合 -AddtoCollection<T> 添加项到集合 :[AddtoCollection]可以将一个项添加到[Collection]集合中 ,[Item]属性用 ...
- webapp框架—学习AngularUI2(demo改造)
目的:把AngularUI的模板应用到“桂电在线”上 步骤如下: 按功能表修改demo界面 学习angularUI如何加载全部页面,为了设置自定义加载模板,在demo/demo.js中找到这一段 // ...
- PHP IP互换数字[转]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Socket 错误总结
错误 因为并没有搞清楚accept函数的使用,所以导致不停的发送失败,同时还不知道错误在哪里,无意中看见errno这个库,可以记录错误的原因,才知道原因在于没有用客户端的套接字进行接收数据,而这个客户 ...
- matlab读取指定路径下的图像
利用matlab读取指定路径下的图像 %% 读入指定路径imgFolder下的图像imgName imgFolder = 'F:\博\快盘\图像+数据\images\文章实验图'; %指定路径 img ...
- struts中如何将前台的值能在action中获取到
如何获取值----三种方式(属性驱动,对象驱动,模型驱动) A:属性驱动 必须生成get,set方法 B:对象驱动 给对象也必须生成get,set方法 c模型驱动 模型驱动需要action去实现 ...
- java-String中的 intern()<转>
1. 首先String不属于8种基本数据类型,String是一个对象. 因为对象的默认值是null,所以String的默认值也是null:但它又是一种特殊的对象,有其它对象没有的一些特性. 2. ne ...