|
|
//---UIScrollViewDelegate
1 @protocol UIScrollViewDelegate<NSObject> 2 3 @optional 4 5 - (void)scrollViewDidScroll:(UIScrollView *)scrollView; // 滾動any offset changes
6 - (void)scrollViewDidZoom:(UIScrollView *)scrollView NS_AVAILABLE_IOS(3_2); // 被縮放 any zoom scale changes
7 8 //開始拖拽 called on start of dragging (may require some time and or distance to move)
9 - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView; 10 // 若是用戶拖動的話被稱爲「手指」。速度是分/毫秒。targetcontentoffset可能改變調整滾動視圖來休息的地方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
11 - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0); 12 //結束拖拽若是它將繼續減速運動以後called on finger up if the user dragged. decelerate is true if it will continue moving afterwards
13 - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate; 14 15 - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView; // 注意:無倫用戶如何滑動scrollView,只要有滑動,就會調scrollViewWillBeginDecelerating,只有scrollView當加速度中止以後,纔會調用scrollViewDidEndDecelerating called on finger up as we are moving 16 - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView; // called when scroll view grinds to a halt 17 18 - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView; // 若是調用called when setContentOffset/scrollRectVisible:animated: finishes. not called if not animating 19 20 - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView; // return a view that will be scaled. if delegate returns nil, nothing happens 21 - (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view NS_AVAILABLE_IOS(3_2); // called before the scroll view begins zooming its content 22 - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale; // scale between minimum and maximum. called after any 'bounce' animations 23 24 - (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView; // return a yes if you want to scroll to the top. if not defined, assumes YES 25 - (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView; // called when scrolling animation finished. may be called immediately if already at top 26 27 @end
@protocol UIScrollViewDelegate<NSObject> @optional - (void)scrollViewDidScroll:(UIScrollView *)scrollView; // 滾動 any offset changes - (void)scrollViewDidZoom:(UIScrollView *)scrollView NS_AVAILABLE_IOS(3_2); // 被縮放 any zoom scale changes // 開始拖拽 called on start of dragging (may require some time and or distance to move) - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView; // 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 - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0); // 手指中止拖拽時調用 called on finger up if the user dragged. decelerate is true if it will continue moving afterwards - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate; - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView; // 手指鬆開後的移動會被調用 called on finger up as we are moving - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView; // called when scroll view grinds to a halt - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView; // 當 動畫(contentOffset和 scrollRect 發生變化時)結束時 ,若是沒有動畫,將不會調用. called when setContentOffset/scrollRectVisible:animated: finishes. not called if not animating - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView; // 返回一個將要被縮放的視圖,若是代理返回 nil ,將不作任何事.return a view that will be scaled. if delegate returns nil, nothing happens - (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view NS_AVAILABLE_IOS(3_2); // 當放大本身的內容時 被調用 called before the scroll view begins zooming its content - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale; // 縮放,任何的彈簧動畫以後被調用. scale between minimum and maximum. called after any 'bounce' animations - (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView; // 若是你想滾動到 the top ,return yes.若是沒有定義,則默認 yes. return a yes if you want to scroll to the top. if not defined, assumes YES - (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView; // 當滾動動畫結束.可能會馬上調用 若是已經 at top .called when scrolling animation finished. may be called immediately if already at top @end
這裏把UIScrollView的幾個要點總結下:代理
從你的手指touch屏幕開始,scrollView開始一個timer,若是:rest
1. 150ms內若是你的手指沒有任何動做,消息就會傳給subView。code
2. 150ms內手指有明顯的滑動(一個swipe動做),scrollView就會滾動,消息不會傳給subView,這裏就是產生問題二的緣由。orm
3. 150ms內手指沒有滑動,scrollView將消息傳給subView,可是以後手指開始滑動,scrollView傳送touchesCancelled消息給subView,而後開始滾動。blog
觀察下tableView的狀況,你先按住一個cell,cell開始高亮,手不要放開,開始滑動,tableView開始滾動,高亮取消。
delaysContentTouches的做用:
這個標誌默認是YES,使用上面的150ms的timer,若是設置爲NO,touch事件當即傳遞給subView,不會有150ms的等待。
cancelsTouches的做用:
這個標準默認爲YES,若是設置爲NO,這消息一旦傳遞給subView,這scroll事件不會再發生。