TableView下拉表头放大 导航栏颜色透明度随着TableView偏移量渐变
2016-07-29 16:45
381 查看
TableView 下拉表头放大
导航栏颜色透明度随着TableView偏移量渐变
用storeboard 布局,之前尝试在storeboard中设置tableview的表头,但是那样弄出来的效果 表头不贴着上面,后来改成storeboard和代码 结合,最后实现的这个效果下载链接: https://github.com/ShaoWenLe/TableViewThe-drop-down-amplification.git
import UIKit let KScreen_Width = UIScreen.mainScreen().bounds.size.width let KScreen_Height = UIScreen.mainScreen().bounds.size.height let imgHeight : CGFloat = 200 class ViewController: UIViewController { @IBOutlet weak var tableView: UITableView! var imageView : UIImageView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. self.navigationController?.navigationBar.barTintColor = UIColor.init(colorLiteralRed: 240/255, green: 240/255, blue: 100/255, alpha: 1) self.navigationController?.navigationBar.alpha = 0 let rightButton = UIButton.init(type: .Custom) rightButton.frame = CGRectMake(KScreen_Width-40, 32, 20, 20) rightButton .setBackgroundImage(UIImage.init(named: "1"), forState: .Normal) rightButton.addTarget(self, action: #selector(ViewController.click), forControlEvents: .TouchUpInside) self.navigationController?.view .addSubview(rightButton) /** 去除导航栏黑线 */ if ((self.navigationController?.navigationBar .respondsToSelector(#selector(self.navigationController?.navigationBar.setBackgroundImage(_:forBarMetrics:)))) != nil){ for view in (self.navigationController?.navigationBar.subviews)! as [UIView] { if view is UIImageView { for view2 in view.subviews { if view2 is UIImageView { view2.hidden = true; } } } } } tableView.contentInset = UIEdgeInsetsMake(imgHeight, 0, 0, 0) imageView = UIImageView.init(frame: CGRectMake(0, -imgHeight, KScreen_Width, imgHeight)) imageView.image = UIImage.init(named: "1468895691727") imageView.contentMode = .ScaleAspectFill tableView .addSubview(imageView) } func scrollViewDidScroll(scrollView: UIScrollView) { let offsetY = scrollView.contentOffset.y let offsetH = imgHeight + offsetY - 20 if offsetH <= 0 { imageView?.frame = CGRectMake(0, -imgHeight+offsetH, KScreen_Width, imgHeight-offsetH) self.navigationController?.navigationBar.alpha = 0 } else { let min = offsetH/(imgHeight-64) < 1 ? offsetH / (imgHeight-64) : 1 self.navigationController?.navigationBar.alpha = min } } // MARK: - Table view data source func numberOfSectionsInTableView(tableView: UITableView) -> Int { // #warning Incomplete implementation, return the number of sections return 1 } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { // #warning Incomplete implementation, return the number of rows return 100 } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) cell.textLabel?.text = String(format: "第%ld行",indexPath.row+1) // Configure the cell... return cell } //右侧按钮点击 func click() { print("点击了按钮") } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
相关文章推荐
- 16、Java并发编程:Timer和TimerTask
- MySQL Table is marked as crashed 解决方法
- springmvc用不了jquery问题解决
- Android Studio 使用git
- 小异全无线办公之自己埋下的雷
- oop 商品信息按商品名称查询 商品按价格排序 内含测试类
- 2016 多校3 1009 Palindrome Bo 回文串dp+优化
- HDu1166敌兵布阵(树状数组)
- 线段树的构造
- 时间联动 动态根据参照时间进行累加
- [机器学习笔记]Note14--推荐系统
- react.js 公共方法 集合
- 常用的linux命令
- url 编码(percentcode 百分号编码)(转载)
- 用正则表达式匹配用rdf3x处理过后的TTL格式文档
- TextView常用功能
- mget 同时获取
- HDU 2072 单词数 (水题我不会,错题集)
- 博客换地方啦,请移步 https://aoenian.github.io/
- POJ1743Musical Theme求解不重叠的最长子串长度(后缀数组+二分求解)