UIScrollView的属性总结
|
|
//---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,如果:
1. 150ms内如果你的手指没有任何动作,消息就会传给subView。
2. 150ms内手指有明显的滑动(一个swipe动作),scrollView就会滚动,消息不会传给subView,这里就是产生问题二的原因。
3. 150ms内手指没有滑动,scrollView将消息传给subView,但是之后手指开始滑动,scrollView传送touchesCancelled消息给subView,然后开始滚动。
观察下tableView的情况,你先按住一个cell,cell开始高亮,手不要放开,开始滑动,tableView开始滚动,高亮取消。
delaysContentTouches的作用:
这个标志默认是YES,使用上面的150ms的timer,如果设置为NO,touch事件立即传递给subView,不会有150ms的等待。
cancelsTouches的作用:
这个标准默认为YES,如果设置为NO,这消息一旦传递给subView,这scroll事件不会再发生。