你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> IOS(Swift)頁面頂部完成拉伸效果代碼

IOS(Swift)頁面頂部完成拉伸效果代碼

編輯:IOS開發綜合

此篇文章將要引見IOS(Swift)頁面頂部完成拉伸效果代碼的相關引見,詳細實例請看下文

  //懶加載      //頂部需求拉伸自定義視圖
    lazy var headView:MyHeaderView = {
        //let hframe = CGRect(x: 0, y: 0, width: swidth, height: swidth/self.imgRation)
        // let hview = Bundle.main.loadNibNamed("MyInfoHeaderView", owner: nil, options: nil)?.first as! MyInfoHeaderView
        //return hview;
    }()
 
    //MARK:1)集合視圖
    self.collectionView?.addSubview(self.headView) 
    override func collectionView(_ collectionView: UICollectionView, cellForItemAt     indexPath: IndexPath) -> UICollectionViewCell {
        if indexPath.section == 0 { //頂部前往一個空的cell
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath)
            return cell
        }
    ....

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        if indexPath.section == 0  {//頂部
            return CGSize(width: swidth, height:200.0 )
        }
....

      //MARK:列表視圖
    self.tableView?.addSubview(self.headView)  
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.section == 0 { //頂部前往一個空的cell
            var cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier)
            return cell!
        }
....

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if indexPath.section == 0{
            return 200.0;
        }
....

    //MARK:拉伸效果完成地位
    override func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let point = scrollView.contentOffset;
        if point.y <= 0 {//下拉
            //self.headView.frame.size.height = swidth/imgRation - point.y
            //self.headView.frame.size.width = self.headView.frame.size.height*imgRation
            //self.headView.frame.origin.x = (swidth - self.headView.frame.size.width)/2
            //self.headView.frame.origin.y =  point.y
            //self.headView.titleImgLeft.constant = 18 - self.headView.frame.origin.x
            //self.mainNavView.backgroundColor = UIColor.clear
            //self.mainNavView.searImg.image = UIImage(named: "搜索框r")
        }else{//上推
           //if point.y >= (self.headView.frame.height - 64){
                //self.mainNavView.searImg.image = UIImage(named: "搜索框w")
                //self.mainNavView.searchText.backgroundColor = UIColor.white
            //}
            //self.headView.titleImgLeft.constant = 18
            // self.mainNavView.backgroundColor = UIColor(red:245/255.0, green:74/255.0, blue:48/255.0, alpha: point.y/(self.headView.frame.height - 64))
        }
    } 

經過本文的學習希望對您理解和學習IOS開發的相關知識有一些好的協助.感激關注本站.我們將為您搜集更多更好的IOS開發教程.

【IOS(Swift)頁面頂部完成拉伸效果代碼】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved