tableView 头部 下拉缩放

方法1:在tableView上层固定一个view用户缩放, 切tableView 设置一个tableHeaderVeiw

具体代码如下:

func scrollViewDidScroll(_scrollView:UIScrollView) {

        lety = scrollView.contentOffset.y

        print("y---->\(y)")

        if y >0 {

            letalphaC = (y +0) / (screenWidth/3*2-64)

            navLabel.textColor = UIColor.black.withAlphaComponent(alphaC)

            navV.backgroundColor = UIColor.white.withAlphaComponent(alphaC)

            self.headerIV.alpha=0

            UIApplication.shared.statusBarStyle = .default

            self.backBtn.setImage( imageLiteral(resourceName: "1_33"), for:UIControl.State.normal)

            self.shareBtn.setTitleColor(UIColor.black, for: UIControl.State.normal)

        }else{

            navLabel.textColor = UIColor.black.withAlphaComponent(0)//UIColor.white

            navV.backgroundColor = UIColor.white.withAlphaComponent(0)//colorSystem

            letscale = ((-y-0) *2+screenWidth/3*2) / (screenWidth/3*2)

            self.headerIV.transform=CGAffineTransform(scaleX: scale, y: scale)

            self.headerIV.alpha=1

            UIApplication.shared.statusBarStyle = .lightContent

            self.backBtn.setImage( imageLiteral(resourceName: "backWhite"), for:UIControl.State.normal)

            self.shareBtn.setTitleColor(UIColor.white, for: UIControl.State.normal)

        }

    }

方法2:直接tableView的tableheaderView ,然后对其做操作

具体代码如下:

func  scrollViewDidScroll(_scrollView:UIScrollView) {

        let y = scrollView.contentOffset.y

        letoffsetY = scrollView.contentOffset.y

        if y >=0{

            letalpha = (y +0) / (screenWidth/3*2-0)

            navV.backgroundColor = UIColor.white.withAlphaComponent(alpha)

            titleL.textColor = UIColor.black.withAlphaComponent(alpha)

            UIApplication.shared.statusBarStyle = .default

            backBtn.setImage( imageLiteral(resourceName: "back_icon"), for:UIControl.State.normal)

            shareBtn.setImage( imageLiteral(resourceName: "share_black"), for:UIControl.State.normal)

            headerSubIV.layer.transform = CATransform3DIdentity

        }else{

            let color = UIColor.white.withAlphaComponent(0)

            navV.backgroundColor= color

            titleL.textColor= color

            letoriginalHeight:CGFloat=screenWidth/3*2

            letscale:CGFloat= (originalHeight - offsetY) / originalHeight

            lettransformScale3D:CATransform3D=CATransform3DMakeScale(scale, scale,1.0)

            lettranslation3D:CATransform3D=CATransform3DMakeTranslation(0, offsetY/2,0)

            headerSubIV.layer.transform=CATransform3DConcat(transformScale3D, translation3D)

            UIApplication.shared.statusBarStyle = .lightContent

            backBtn.setImage( imageLiteral(resourceName: "back_white_icon"), for:UIControl.State.normal)

            shareBtn.setImage( imageLiteral(resourceName: "share_white"), for:UIControl.State.normal)

        }

    }

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值