1:首先定义三个变量有待使用
CGFloat contentOffsetY;
CGFloat oldContentOffsetY;
CGFloat newContentOffsetY;
2:此方法我是在分类列表:向上滚动的时候动画隐藏上方状态栏,向下滚动的时候显示上方状态栏,并且tableView还有数据
#pragma mark UIScrollViewDelegate 协议方法
#pragma mark 正在滚动 滚动时调用此方法(手指离开屏幕后)
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
_pageBtn.hidden = NO;
newContentOffsetY = scrollView.contentOffset.y;
if (newContentOffsetY > oldContentOffsetY && oldContentOffsetY > contentOffsetY) {
// 向上滚动
[UIView animateWithDuration:0.5 animations:^{
_upWholeView.frame = CGRectMake(0, -104, kScreenWidth, 84);
goodListTableView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
goodsListCollectionView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
}];
} else if (newContentOffsetY < oldContentOffsetY && oldContentOffsetY < contentOffsetY) {
// 向下滚动
[UIView animateWithDuration:0.5 animations:^{
_upWholeView.frame = CGRectMake(0, 20, kScreenWidth, 84);
goodListTableView.frame = CGRectMake(0, 104, kScreenWidth, kScreenHeight-104);
goodsListCollectionView.frame = CGRectMake(0, 104, kScreenWidth, kScreenHeight-104);
}];
} else {
//拖拽
}
if (scrollView.dragging) {
// 拖拽
if ((scrollView.contentOffset.y - contentOffsetY) > 5.0f) {
// 向上拖拽
[UIView animateWithDuration:0.5 animations:^{
_upWholeView.frame = CGRectMake(0, -104, kScreenWidth, 84);
goodListTableView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
goodsListCollectionView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
}];
} else if ((contentOffsetY - scrollView.contentOffset.y) > 5.0f) {
// 向下拖拽
[UIView animateWithDuration:0.5 animations:^{
_upWholeView.frame = CGRectMake(0, 20, kScreenWidth, 84);
goodListTableView.frame = CGRectMake(0, 104, kScreenWidth, kScreenHeight-104);
goodsListCollectionView.frame = CGRectMake(0, 104, kScreenWidth, kScreenHeight-104);
}];
} else {
//滚动
}
}
}
#pragma mark 开始拖拽视图
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
contentOffsetY = scrollView.contentOffset.y;
}
#pragma mark 自己滚动停止
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
_pageBtn.hidden = YES;
}
#pragma mark 手动让其停止 完成拖拽(滚动停止时调用此方法,手指离开屏幕前)
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
_pageBtn.hidden = YES;
oldContentOffsetY = scrollView.contentOffset.y;
}