[10秒学会] - iOS tableView中headView和footView悬停方式
2016-05-12 00:00
375 查看
摘要: [10秒学会] - iOS tableView中headView和footView悬停方式
效果图头部悬停 底部不悬停
![](http://static.oschina.net/uploads/space/2016/0512/171328_vKLA_1186234.gif)
一共4种
一: 2个都悬停 UITableViewStylePlain //没什么好疑问的
二:2个都不悬停 UITableViewStyleGrouped //也没啥好疑问的
三:头部不悬停 底部悬停 使用UITableViewStylePlain //网上已经很多这个代码 还是贴一下吧
四 才是今天我们的重点 头部悬停 底部不悬停
效果图头部悬停 底部不悬停
![](http://static.oschina.net/uploads/space/2016/0512/171328_vKLA_1186234.gif)
一共4种
一: 2个都悬停 UITableViewStylePlain //没什么好疑问的
二:2个都不悬停 UITableViewStyleGrouped //也没啥好疑问的
三:头部不悬停 底部悬停 使用UITableViewStylePlain //网上已经很多这个代码 还是贴一下吧
[code=plain]-(void)scrollViewDidScroll:(UIScrollView *)scrollView { // if (scrollView == self.myTableView) { //YOUR_HEIGHT 为最高的那个headerView的高度 // CGFloat sectionHeaderHeight = 20; 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); } } }
四 才是今天我们的重点 头部悬停 底部不悬停
[code=plain] self.tableView.contentInset = UIEdgeInsetsMake(0, 0, -105, 0); //首先改变内边距 -105是底部的距离 CGRect rectInTableView = [self.tableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:5 inSection:2]]; //现在是写死的 你可以根据模型数据 写成变量 CGRect rect = [self.tableView convertRect:rectInTableView toView:[self.tableView superview]];//这是是最后cell row的高度 if(rect.origin.y<=-1288){ //-1288 这个位置 是可以根据你的位置调整出来 self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0); }else{ self.tableView.contentInset = UIEdgeInsetsMake(0, 0, -105, 0); }
相关文章推荐
- iOS开发添加楷体字体(图解)
- iOS mvvm 框架设计
- iOS手势识别:识别原理和自定义手势识别
- 解决niosII中下载提示Connected system ID hash not found on target at expected base address问题
- iOS键盘弹出 视图向上滚动键盘高度
- 切换存储文件 (翻译)
- iOS 获取手机的型号,系统版本,软件名称,软件版本
- iOS开发 -关于使用iOS沙盒路径遇到的问题
- iOS Cocoapods安装
- iOS之XMPP环境搭建
- iOS 延迟执行的几种方式 —— HERO博客
- iOS 杂笔-22(万年一遇~一张图片对代理的理解)
- ios 拨打电话系统回调函数
- iOS JsonModel
- iOS之CoreData基本使用以及简单封装
- iOS中的正则表达式运用
- 实用知识:iOS5.0前加速计的方法使用(了解)
- iOS数据持久化
- iOS run loop详解
- iOS照相机获取到的图片自动旋转90度解决办法