iOS parallaxView实现方式总结-个人中心背景效果

释放双眼,带上耳机,听听看~!

方法一:不对显示的图片的尺寸做特殊处理

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView != self.tableView) {
return;
}
CGFloat coverOriginalHeight = CGRectGetHeight(self.converImageView.superview.frame);
if (scrollView.contentOffset.y < 0) {
CGFloat scale = (fabs(scrollView.contentOffset.y) + coverOriginalHeight) / coverOriginalHeight;
CATransform3D transformScale3D = CATransform3DMakeScale(scale, scale, 1.0);
CATransform3D transformTranslate3D = CATransform3DMakeTranslation(0, scrollView.contentOffset.y/2, 0);
self.converImageView.layer.transform = CATransform3DConcat(transformScale3D, transformTranslate3D);
UIEdgeInsets scrollIndicatorInsets = scrollView.scrollIndicatorInsets;
scrollIndicatorInsets.top = fabs(scrollView.contentOffset.y) + coverOriginalHeight;
scrollView.scrollIndicatorInsets = scrollIndicatorInsets;
}
else {
self.converImageView.layer.transform = CATransform3DIdentity;
if (scrollView.scrollIndicatorInsets.top != coverOriginalHeight) {
UIEdgeInsets scrollIndicatorInsets = scrollView.scrollIndicatorInsets;
scrollIndicatorInsets.top = coverOriginalHeight;
scrollView.scrollIndicatorInsets = scrollIndicatorInsets;
}
}
}

方法二:设置背景 图片为tableView的headerView,
‘- (void)scrollViewDidScroll:(UIScrollView *)scrollView ‘中改变ImgView的frame.headerView的clipsToBounds 设为NO

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat offsetY = scrollView.contentOffset.y;
[self.headerView layoutSubViewWhenScroll:offsetY];
}
- (void)layoutSubViewWhenScroll:(CGFloat) offsetY {
CGRect rect = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
rect.origin.y += offsetY;
rect.size.height -= offsetY;
self.bgImgView.frame = rect;
}

方法三:修改tableView的contentInset在’- (void)scrollViewDidScroll:(UIScrollView *)scrollView 中随时改变contentInset

详细的代码见:https://github.com/xinyuly/XYUserCenterAnimation

人已赞赏
iOS文章

iOS 根据文本内容调整Button大小

2020-2-22 13:24:31

iOS文章

iOS中的runtime应用

2020-2-22 15:33:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索