方法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)
}
}