方法一 根据滚动速度显示或隐藏效果
-
(void)scrollViewDidScroll:(UIScrollView *)scrollView{
UIPanGestureRecognizer *pan = scrollView.panGestureRecognizer;
//获取到拖拽的速度 >0 向下拖动 <0 向上拖动
CGFloat velocity = [pan velocityInView:scrollView].y;[UIView animateWithDuration:1.5f animations:^{
//向上拖动,隐藏导航栏
if (velocity < -5) {
self.rcsPersonDetailInfoViewControllerNavigationBarView.hidden = YES;
//向下拖动,显示导航栏
}else if (velocity > 5){
self.rcsPersonDetailInfoViewControllerNavigationBarView.hidden = NO;
}else if(velocity == 0){}
} completion:^(BOOL finished) {
}];
}
方法二 根据滚动偏移量
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
//获取偏移
CGFloat offsetY = scrollView.contentOffset.y + self.rcsPersonInfoTableView.contentInset.top;
CGFloat panTranslationY = [scrollView.panGestureRecognizer translationInView:self.rcsPersonInfoTableView].y;
if (offsetY > 200) {
if (panTranslationY > 0) {
//下滑趋势,显示
[UIView animateWithDuration:1.5f animations:^{
self.rcsPersonDetailInfoViewControllerNavigationBarView.hidden = NO;
}];
//向上拖动,隐藏导航栏
}else if(panTranslationY < 0){[UIView animateWithDuration:1.5f animations:^{ self.rcsPersonDetailInfoViewControllerNavigationBarView.hidden = YES; }]; }
}else{
self.rcsPersonDetailInfoViewControllerNavigationBarView.hidden = NO;
}
}
网友评论