iOS开发笔记--去掉tableview中section的headerview粘性
2015-12-08 16:03
441 查看
ios的tableview中headerview会随着滑动黏在上方,直到新的sectionheaderview出现并替换掉,这是个好的特性,但是在为了实现PM某些需求的时候,又不是很符合心意,在网上查了下,找到了其解决方法:
[objc] view
plaincopy
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/9e12f1d3e499fc949c886e7c9e0484f9)
// 去掉UItableview headerview黏性(sticky)
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat sectionHeaderHeight = 40;
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);
}
}
利用控制scrollView的滑动来控制headView显示与否。
[objc] view
plaincopy
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
// 去掉UItableview headerview黏性(sticky)
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat sectionHeaderHeight = 40;
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);
}
}
利用控制scrollView的滑动来控制headView显示与否。
相关文章推荐
- 使用ios系统自带分享
- 需求 - 11 - 等待动画
- iOS开发之block(二)
- IOS:两种回调的方式实现(delegate和block)
- iOS常用的公共方法详解
- iOS计算上次日期距离现在多久的代码
- mono在ios平台的局限性
- nagios安装
- ios开发创建证书和描述文件的整个流程
- ios 里如何判断当前应用的定位服务是否可用
- iOS自动布局实现Cell和Tableview高度自适应(SDAutoLayout)
- <iOS>git-起步
- iOS 控件
- 学习iOS的见解
- ios-kvc\kvo 用法
- iOS-初级数据持久化
- IOS开发copy,nonatomic, retain,weak,strong用法
- 自用cocoapods命令整合
- iOS第三方开源库
- ios属性修饰符总结