@implementation XXXViewController{
CGFloat contentOffsetX;
CGFloat statrContentOffsetX;
CGFloat endContentOffsetX;
}
```
//拖动之前坐标
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
contentOffsetX = scrollView.contentOffset.x;
}
```
```
//拖动即将结束时的坐标
-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
startContentOffsetX = scrollView.contentOffset.x;
}
```
```
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
endContentOffsetX = scrollView.contentOffset.x;
//从右向左滑动
if (endContentOffsetX > startContentOffsetX && startContentOffsetX > contentOffsetX) {
NSLog(@" 注意了,左滑了");
}
if (endContentOffsetX < startContentOffsetX && startContentOffsetX < contentOffsetX){ //从左向右滑动
NSLog(@" 注意了,右滑了");
}
}
```
***提示***
将x换成y就可判断向上或者向下滑动了
网友评论