IOS(Swift)頁面頂部實現展開效果代碼,iosswift

來源:互聯網
上載者:User

IOS(Swift)頁面頂部實現展開效果代碼,iosswift

  //懶載入    
  //頂部需要展開自訂視圖 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)) } } 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.