UIScrollView监听静止的数种情况

1.直接通过block

-(void)testInBlock
{
    //通过block监听
    [UIView animateWithDuration:1.0 animations:^{
        self.scrollView.contentOffset = CGPointMake(50, 20);
    } completion:^(BOOL finished) {
        NSLog(@"滚动完毕");
    }];
}

2.代理中的 scrollViewDidEndScrollingAnimation:方法
触发条件:使用setContentOffset:animated:或者scrollRectToVisible:animated:方法让scrollView产生滚动动画

-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
    NSLog(@"静止-[使用setContentOffset:animated:或者scrollRectToVisible:animated:方法让scrollView产生滚动动画, 最后静止]");
}

3.代理中的scrollViewDidEndDecelerating:方法
触发条件:人为拖拽scrollView产生滚动动画(手松开以后由于惯性会继续滚动)

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSLog(@"静止-[手松开以后由于惯性继续滚动, 最后静止]");
}

4.代理中的scrollViewDidEndDragging: willDecelerate:方法
decelerate为YES : 手松开后会由于惯性继续滚动;NO : 手松开后立即静止

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    if (decelerate) {
        NSLog(@"手松开后由于惯性继续滚动");
    } else { // 手松开后立即静止
        NSLog(@"静止-[手松开后立即静止]");
        [self afterIdle];
    }
}
posted on 2016-01-14 23:14  夏鲁鲁  阅读(310)  评论(0编辑  收藏  举报