Swift3 页面顶部实现拉伸效果代码

  //懒加载    
  //顶部需要拉伸自定义视图 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:2)列表视图 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)) } } 

转载于:https://www.cnblogs.com/mapanguan/p/6386868.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值