判断UIScrollView滚动方向, 以下是 "判断上下" 的代码
float lastContentOffset;
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
lastContentOffset = scrollView.contentOffset.y;
}
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
if (lastContentOffset < scrollView.contentOffset.y) {
[UIView animateWithDuration:0.5 animations:^{
self.headerViewTopConstraint.constant = -self.headerView.frame.size.height;
[self.headerView layoutIfNeeded];
}];
}else{
JXLog(@"向下滚动");
[UIView animateWithDuration:0.1 animations:^{
self.headerViewTopConstraint.constant = 0;
[self.headerView layoutIfNeeded];
}];
}
左右同理判断换成 :
scrollView.contentOffset.x
UIView的Animation无效
只需要在动画代码块调用UIView的
[self.view layoutIfNeeded];
方法即可
网友评论