监听scollView滑动 判断向上/向下滑动
先创建一个全局变量
float _currentPostion;
让监听的控件去遵循协议
设置scrollView 的代理方法
#pragma mark -----监听scollView 的滑动范围
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat pageWidth = self.collectionViews.frame.size.height;
CGFloat currentPostion =self.collectionViews.contentOffset.y;
NSInteger page = currentPostion / pageWidth;
if (page >= 1) {
if (currentPostion - _lastPosition > 25) {
_lastPosition = currentPostion;
NSLog(@"ScrollUp now");
self.backTop.layer.hidden = YES;
}else if (_lastPosition - currentPostion > 25){
_lastPosition = currentPostion;
NSLog(@"ScrollDown now");
self.backTop.layer.hidden = NO;
}
}else{
self.backTop.layer.hidden = YES;
}
}
同样我没也可以利用scrollView的代理方法监听x的滑动来实现禁止滑动或滑动跳转其他页/或返回其他页!
监听scollView滑动 判断向上/向下滑动