UIScrollViewDelegate协议方法

Posted cchhers

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UIScrollViewDelegate协议方法相关的知识,希望对你有一定的参考价值。

#pragma mark 监听滚动停止

// called on start of dragging (may require some time and or distance to move)
// 开始拖动时调用(可能需要一些时间或距离才能移动)
// 开始拖动时(手指在屏幕上)
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    NSLog(@"111~~~~~~~~~~scrollViewWillBeginDragging:%ld", (long)scrollView.contentOffset.y);
}

// any offset changes
// 任何偏移更改
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    NSLog(@"222~~~~~~~~~~scrollViewDidScroll:%ld", (long)scrollView.contentOffset.y);
}

// called on finger up if the user dragged. velocity is in points/millisecond. targetContentOffset may be changed to adjust where the scroll view comes to rest
// 如果用户拖动,则调用finger up。速度以点/毫秒为单位。可以更改targetContentOffset以调整滚动视图的静止位置
// 结束拖动时(手指离开屏幕)的速度(正-往上的速度,负-往下的速度)
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
    NSLog(@"333~~~~~~~~~~scrollViewWillEndDragging:%ld, velocity:%lf", (long)scrollView.contentOffset.y, velocity.y);
}

// called on finger up if the user dragged. decelerate is true if it will continue moving afterwards
// 如果用户拖动,则调用finger up。如果减速后继续移动,则为真
// 拖动完之后,如果会滑行,则为真
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    NSLog(@"444~~~~~~~~~~scrollViewDidEndDecelerating:%ld, decelerate:%d", (long)scrollView.contentOffset.y, decelerate);
}

// called on finger up as we are moving
// 当我们移动的时候手指向上
// 开始滑行
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
    NSLog(@"555~~~~~~~~~~scrollViewWillBeginDecelerating:%ld", (long)scrollView.contentOffset.y);
}

// called when scroll view grinds to a halt
// 当scroll view磨合停止时调用
// 停止滑行
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    NSLog(@"666~~~~~~~~~~scrollViewDidEndDecelerating:%ld", (long)scrollView.contentOffset.y);
}

// called when setContentOffset/scrollRectVisible:animated: finishes. not called if not animating
// 当setContentOffset/scrollRectVisible:animated:finishes完成时调用。如果不设置动画,则不调用
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
 NSLog(@"777~~~~~~~~~~scrollViewDidEndScrollingAnimation:%ld", (long)scrollView.contentOffset.y);
}

// called when scrolling animation finished. may be called immediately if already at top
// 当滚动动画完成时调用。如果已经在顶部,可以立即调用
// 当点击状态栏tableView回到顶部时调用
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView {
    NSLog(@"888~~~~~~~~~~scrollViewDidScrollToTop:%ld", (long)scrollView.contentOffset.y);
}

// Also see -[UIScrollView adjustedContentInsetDidChange]
// tableView刚出现时会调用
- (void)scrollViewDidChangeAdjustedContentInset:(UIScrollView *)scrollView {
    NSLog(@"999~~~~~~~~~~scrollViewDidChangeAdjustedContentInset:%ld", (long)scrollView.contentOffset.y);
}

// return a yes if you want to scroll to the top. if not defined, assumes YES
// 如果要滚动到顶部,请返回“是”。如果没有定义,则假设是
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView {
    return YES;
}

 

以上是关于UIScrollViewDelegate协议方法的主要内容,如果未能解决你的问题,请参考以下文章

未调用 UIScrollViewDelegate 函数

UIScrollViewDelegate 不触发方法

UIScrollViewDelegate 方法中的重复代码

如何使用 UIScrollViewDelegate 方法重新实现 UIScrollView 分页

UIScrollViewDelegate 中的委托方法不响应表格视图滚动事件

覆盖scrollViewDidScroll时的问题,但不是UIScrollViewDelegate的所有其他方法