判断 TableView 滚动方向

作者: __将离 | 来源:发表于2015-06-20 23:21 被阅读0次

  在 iOS 中,我们往往会根据 tableview 的滚动方向来影藏或者显示放在顶部或者地步的view。

  因为 tableview 继承于 scrollview,所以只需要在代理方法里判断一下偏移量的值就可以了。

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{

CGPoint translation = [scrollView.panGestureRecognizer translationInView:scrollView.superview];

if (translation.y>0) {

[UIView animateWithDuration:0.3 animations:^{

self.topView.frame = CGRectMake(0, 0, 320, 64);

self.footView.frame = CGRectMake(0, 568 - 40, 320, 40);

}];

}else if(translation.y<0){

[UIView animateWithDuration:0.3 animations:^{

self.topView.frame = CGRectMake(0, -64, 320, 64);

self.footView.frame = CGRectMake(0, 568, 320, 40);

}];

}

}

相关文章

网友评论

    本文标题:判断 TableView 滚动方向

    本文链接:https://www.haomeiwen.com/subject/mtisqttx.html