最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ios實(shí)現(xiàn)tableView頂部彈簧圖片效果

 更新時(shí)間:2017年08月02日 15:50:05   作者:Kamto  
這篇文章主要為大家詳細(xì)介紹了ios實(shí)現(xiàn)tableView頂部彈簧圖片效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

大家可能注意到有些tableView的頂部圖片,會(huì)隨著你拉伸而跟著拉伸變大。本文實(shí)例為大家分享了ios實(shí)現(xiàn)tableView頂部“彈簧”圖片,供大家參考,具體內(nèi)容如下

一種思路是將圖片放置tableView的tableHeaderView上當(dāng)tablview下移改變圖片的frame達(dá)到效果。當(dāng)然這個(gè)效果特別簡(jiǎn)單,高手可以略過。

代碼如下

import UIKit

class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {

 lazy var myTableView : UITableView! = {
  var tableView = UITableView.init(frame: self.view.frame,style:UITableViewStyle.plain)
  tableView.delegate = self
  tableView.dataSource = self
  tableView.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: "mycell")
  return tableView
 }()
 
 var headerImageView:UIImageView?
 var headerView:UIView?
 var headerViewHeight:CGFloat = 0.0
 
 
 override func viewDidLoad() {
  super.viewDidLoad()
  // Do any additional setup after loading the view, typically from a nib.
  setupUI()
 }

 func setupUI(){
  headerView = UIView.init(frame: CGRect(x:0,y:0,width:self.view.frame.width,height:300))
  headerViewHeight = headerView!.frame.height;
  self.view.addSubview(headerView!)
  headerImageView = UIImageView.init(frame: headerView!.frame)
  headerImageView?.image = UIImage.init(named: "bg-mine")
  headerView?.addSubview(headerImageView!)
  myTableView.tableHeaderView = headerView
  self.view.addSubview(myTableView)
  
 }
 

 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  return 2
 }
 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  let cell:UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "mycell", for: indexPath)
  cell.textLabel?.text = "測(cè)試"
  return cell
 }
 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  return 50
 }
 
 func scrollViewDidScroll(_ scrollView: UIScrollView) {
  let contentOffSetY = scrollView.contentOffset.y
  if contentOffSetY < 0 {
   var rect = headerView?.frame
   rect?.size.height = headerViewHeight - contentOffSetY
   let headerViewWidth = headerView?.frame.size.width
   rect?.size.width = headerViewWidth!*(headerViewHeight-contentOffSetY)/headerViewHeight
   rect?.origin.x = -((rect?.size.width)! - headerViewWidth!)/2
   rect?.origin.y = contentOffSetY
   headerView?.frame = rect!
   headerImageView?.frame = rect!
  } 
 }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

塔河县| 六安市| 婺源县| 两当县| 伊金霍洛旗| 灵丘县| 津南区| 汾阳市| 石景山区| 睢宁县| 建昌县| 凤庆县| 楚雄市| 德令哈市| 布尔津县| 广安市| 通江县| 金溪县| 博兴县| 新乡县| 柘荣县| 林口县| 合阳县| 十堰市| 巴马| 隆回县| 襄垣县| 城口县| 肥城市| 永清县| 科技| 菏泽市| 昆山市| 商水县| 邮箱| 彭州市| 桓仁| 九江县| 迭部县| 乌拉特后旗| 衡东县|