@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]app