关闭

关于UIScrollViewDelegate协议中每个回调函数的意义及执行顺序的理解

标签: UIScrollViewDelegateUIScrollView
660人阅读 评论(0) 收藏 举报
分类:
@protocol UIScrollViewDelegate<NSObject>

@optional

- (void)scrollViewDidScroll:(UIScrollView *)scrollView;  // 只要view有滚动(不管是拖、拉、放大、缩小  等导致) 都会执行此函数---any offset changes

- (void)scrollViewDidZoom:(UIScrollView *)scrollView__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2); // view的缩放,参考另一篇博文---any zoom scale changes

// called on start of dragging (may require some time and or distance to move)
// 将要开始拖拽,手指已经放在view上并准备拖动的那一刻
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;

// called on finger up if the user dragged. velocity is in points/second. targetContentOffset may be changed to adjust where the scroll view comes to rest. not called when pagingEnabled is YES
// 将要结束拖拽,手指已拖动过view并准备离开手指的那一刻  注意:当属性pagingEnabled为YES时此函数不被调用
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);

// called on finger up if the user dragged. decelerate is true if it will continue moving afterwards
// 已经结束拖拽,手指刚离开view的那一刻
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;

// called on finger up as we are moving
//  view将要开始减速 view滑动之后有惯性 
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;

// called when scroll view grinds to a halt
// view已经停止滚动 
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;     

// called when setContentOffset/scrollRectVisible:animated: finishes. not called if not animating
// 有动画时调用
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView;

// return a view that will be scaled. if delegate returns nil, nothing happens
// 直接看英文吧
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;  

// called before the scroll view begins zooming its content 
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2);

 // scale between minimum and maximum. called after any 'bounce' animations
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale;

// return a yes if you want to scroll to the top. if not defined, assumes YES
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView;

// called when scrolling animation finished. may be called immediately if already at top 
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView;     

@end

执行顺序:
willBeginDragging
DidScroll
willEndDragging
DidEndDragging
DidScroll
willBeginDecelerating
DidScroll
DidEndDecelerating

#define DELEGATE_CALLBACK(DELEGATE, SEL) if (DELEGATE && [DELEGATE respondsToSelector:@selector(SEL)]) [DELEGATE performSelector:@selector(SEL)]
#define DELEGATE_CALLBACK_ONE_PARAMETER(DELEGATE, SEL, X) if (DELEGATE && [DELEGATE respondsToSelector:@selector(SEL)]) [DELEGATE performSelector:@selector(SEL) withObject:X]

#define DELEGATE_CALLBACK_TWO_PARAMETER(DELEGATE, SEL, X, Y) if (DELEGATE && [DELEGATE respondsToSelector:@selector(SEL)]) [DELEGATE performSelector:@selector(SEL) withObject:X withObject:Y]

(转自:http://blog.sina.com.cn/s/blog_74e9d98d010154x3.html)

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:234644次
    • 积分:3259
    • 等级:
    • 排名:第10455名
    • 原创:74篇
    • 转载:129篇
    • 译文:0篇
    • 评论:12条
    最新评论