首页 > 代码库 > UIScrollViewDelegate详解

UIScrollViewDelegate详解

UIScrollViewDelegate会经常用到,在这里对代理协议所包含的方法简单描述,以便于以后使用

几个概念的理解:
contentSize:可滑动区域的大小
contentOffset:滑动视图里面的内容的相对位置
contentInset:滑动视图在外面的相对位置

1、只要view有滚动(不管是拖、拉、放大、缩小等导致)都会执行此函数
-(void)scrollViewDidScroll:(UIScrollView *)scrollView;
2、将要开始拖拽,手指已经放在view上并准备拖动的那一刻
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
3、将要结束拖拽,手指已拖动过view并准备离开手指的那一刻,注意:当属性pagingEnabled为YES时,此函数不被调用
-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset;
4、已经结束拖拽,手指刚离开view的那一刻
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
5、view将要开始减速,view滑动之后有惯性
-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;
6、view已经停止滚动
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
7、view的缩放
-(void)scrollViewDidZoom:(UIScrollView *)scrollView
8、有动画时调用
-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView

UIScrollViewDelegate详解