关于UIScrollViewDelegate协议中每个回调函数的意义及执行顺序的理解
@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]
@optional
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
- (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)scrollViewWillBeginDragg
// 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并准备离开手指的那一刻
- (void)scrollViewWillEndDraggin
// called on finger up if the user dragged. decelerate is true if it will continue moving afterwards
// 已经结束拖拽,手指刚离开view的那一刻
- (void)scrollViewDidEndDragging
// called on finger up as we are moving
//
- (void)scrollViewWillBeginDecel
// called when scroll view grinds to a halt
// view已经停止滚动
- (void)scrollViewDidEndDecelera
// called when setContentOffset/scrollRectVisible:animated: finishes. not called if not animating
// 有动画时调用
- (void)scrollViewDidEndScrollin
// return a view that will be scaled. if delegate returns nil, nothing happens
// 直接看英文吧
- (UIView *)viewForZoomingInScrollVi
// called before the scroll view begins zooming its content
- (void)scrollViewWillBeginZoomi
- (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)scrollViewShouldScrollTo
// called when scrolling animation finished. may be called immediately if already at top
- (void)scrollViewDidScrollToTop
@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]
网络上志同道合,我们一起学习网络安全,一起进步,QQ群:694839022