tableView内的View悬停在导航栏的效果
来源:互联网 发布:安知玉如意百度云 编辑:程序博客网 时间:2024/06/02 23:36
首先看看效果,我只是做了一个demo
里面的view我只是用了一个很普通的label来代表,要具体用其他控件可以随意
上过程了
首先下面我建立了一个controller 里面包含了一个UITableview 上面红色范围内的是tableView的HeaderView 下面重复的很多文字是Cell
controller 我就不细说了 把代码展示出来
TestViewController.swift
import UIKitclass TestViewController: UIViewController { @IBOutlet weak var tableView: UITableView! var header = Bundle.main.loadNibNamed("TestTableViewHeaderView", owner: nil, options: nil)!.last as! TestTableViewHeaderView convenience init() { self.init(nibName: "TestViewController", bundle: Bundle.main) } override func viewDidLoad() { super.viewDidLoad() tableView.register(UINib(nibName: "TestTableViewCell", bundle: Bundle.main), forCellReuseIdentifier: "TestTableViewCell") tableView.estimatedRowHeight = 50 tableView.rowHeight = UITableViewAutomaticDimension tableView.estimatedSectionHeaderHeight = 50 tableView.sectionHeaderHeight = UITableViewAutomaticDimension // Do any additional setup after loading the view. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. }}extension TestViewController:UITableViewDataSource,UITableViewDelegate{ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 10 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "TestTableViewCell") as! TestTableViewCell return cell } func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { return header }}extension TestViewController:UIScrollViewDelegate{ func scrollViewDidScroll(_ scrollView: UIScrollView) { header.refreshFloatViewFrame() }}
cell的代码我就不用展示了 那个无所谓的 下面展示header的代码
class TestTableViewHeaderView: UIView { @IBOutlet weak var floatViewConstainerView: UIView! @IBOutlet weak var floatView: UILabel! func refreshFloatViewFrame() { if floatView.superview == floatViewConstainerView && floatViewConstainerView.window != nil { (UIApplication.shared.delegate as! AppDelegate).window!.addSubview(floatView) } floatView.bounds = floatViewConstainerView.bounds var directionCenter = floatViewConstainerView.getPositionInWindow(CGPoint(x: floatView.bounds.width/2, y: floatView.bounds.height/2)) if directionCenter != nil { directionCenter?.y = (directionCenter!.y < 42 ? 42 : directionCenter!.y) }else{ directionCenter = CGPoint(x: UIScreen.main.bounds.width/2, y: 42) } floatView.center = directionCenter! }}
headerView的布局文件不重要 也给看一下吧
当然 你要用的话还得添加一些代码,比如说这个controller的appear和disappear 你必须要把这个浮动的view给放回去 你肯定是需要在HeaderView里面写两个函数实现一下的
本人很希望能够与更多人共享知识,我的做法有可能不是很好,希望有更好的办法的时候来评论说一下,让大家都能够知道更好的方法,转载请注明出处
0 0
- tableView内的View悬停在导航栏的效果
- andorid ScrollView内layout的悬停效果
- 取消TableView的headerView和footerView的悬停效果
- 导航栏悬停效果制作
- 隐藏导航栏时添加在self.view上的Tableview位置产生20个单位的误差
- view里面的tableview顶部被view的导航栏盖住了的问题
- 可以实现导航栏内的某个内容和他的下层进行悬停出现和隐藏
- 自定义视图 自定义代理在tableView视图内形成一个加载信息的效果
- 在Ext的GridPanel中添加鼠标悬停的效果
- 在Ext的GridPanel中添加鼠标悬停的效果
- 在Ext的GridPanel中添加鼠标悬停的效果
- Android滑动ScrollView时使导航栏停留的效果(仿ios的tableview分区)
- 流行的鼠标悬停效果
- 其他的CSS3悬停效果
- jQuery的滚动悬停效果
- UICollectionView的头部悬停效果
- 简单的鼠标悬停效果
- 简单的鼠标悬停效果
- linux 线程控制
- ELK用户管理
- Codeforces 742A Arpa’s hard exam and Mehrdad’s naive cheat 打表+水题
- Redis数据类型-String
- 大数 斐波那契 与阶乘
- tableView内的View悬停在导航栏的效果
- 常见的Python面试题+详细解答
- Python爬虫爬取Html中的Url常用知识
- spring mvc <mvc:annotation-driven/> 和<context:component-scan base-package=""/>解释
- Redis数据类型-List
- 修复miniblink无法显示某个网站的某个图标的bug
- Codeforces 742B B. Arpa’s obvious problem and Mehrdad’s terrible solution
- android入门小知识
- Tablayout使用小结