chenghuang
2016-05-19 20:36:12 +08:00
完美实验。。。
首先加一个 headerview 在 tableview 上,高度 0.然后假设上面的广告栏为 100 ,增加下面代码
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGRect rect = scrollView.frame;
if (rect.origin.y > 0) {
self.header.frame =CGRectMake(0, 0, self.view.bounds.size.width, scrollView.contentOffset.y);
self.collectionView.tableHeaderView = self.header;
scrollView.frame = CGRectMake(0, 100 - scrollView.contentOffset.y, self.view.bounds.size.width, self.view.bounds.size.height);
}else{
if (scrollView.contentOffset.y <= 100) {
self.header.frame =CGRectMake(0, 0, self.view.bounds.size.width, scrollView.contentOffset.y);
self.collectionView.tableHeaderView = self.header;
scrollView.frame = CGRectMake(0, 100 - scrollView.contentOffset.y, self.view.bounds.size.width, self.view.bounds.size.height);
}
}
}