关于顶部图片下拉放大,设置UITableView的headerView实现,UITableView继承自UIScrollView,同样的设置UIScrollView的顶部图片也可以实现同样的效果
这里使用Xib创建HerderView:
1、声明:
@property (strong,nonatomic) CityFaceBookHearView *CityFaceBookHeaderView;
2、懒加载初始化
-(CityFaceBookHearView *)CityFaceBookHeaderView{
if (_CityFaceBookHeaderView == nil) {
_CityFaceBookHeaderView = [[[NSBundle mainBundle] loadNibNamed:@"CityFaceBookHearView" owner:0 options:nil]lastObject];
}
return _CityFaceBookHeaderView;
}
3、关联
self.CityFaceBookHeaderView.bgImageView.clipsToBounds=YES;
self.CityFaceBookHeaderView.bgImageView.contentMode=UIViewContentModeScaleAspectFill;
self.CityFaceBookHeaderView.bgImageView.image = [UIImage imageNamed:@"Default@180"]; // 默认图
self.tableView.tableHeaderView=self.CityFaceBookHeaderView;
4、数据刷新
[self.CityFaceBookHeaderView configWithData:_dataHeaderViewModel didSelectSaygoodBtnBlock:^{
// do something
}];
5、UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offsetY = scrollView.contentOffset.y;
if (offsetY < 0) {
self.CityFaceBookHeaderView.bgImageView.frame = CGRectMake(offsetY/2, offsetY, _CityFaceBookHeaderView.width - offsetY, _CityFaceBookHeaderView.height - offsetY); // 修改头部的frame值就行了
}
}
网友评论