TableView下拉表頭放大 導覽列顏色透明度隨著TableView位移量漸層

來源:互聯網
上載者:User

標籤:

TableView 下拉表頭放大導覽列顏色透明度隨著TableView位移量漸層

用storeboard 布局,之前嘗試在storeboard中設定tableview的表頭,但是那樣弄出來的效果 表頭不貼著上面,後來改成storeboard和代碼 結合,最後實現的這個效果

 

 

下載連結: https://github.com/ShaoWenLe/TableViewThe-drop-down-amplification.git

import UIKitlet KScreen_Width = UIScreen.mainScreen().bounds.size.widthlet KScreen_Height = UIScreen.mainScreen().bounds.size.heightlet imgHeight : CGFloat = 200class 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.    }}

 

TableView下拉表頭放大 導覽列顏色透明度隨著TableView位移量漸層

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.