|
这里把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事件不会再发生
contentSize是scrollview可以滚动的区域,比如frame = (0 ,0 ,320,480) contentSize = (320,960),代表你的scrollview可以上下滚动,滚动区域为frame大小的两倍。
contentOffset是scrollview当前显示区域顶点相对于frame顶点的偏移量,比如上个例子你拉到最下面,contentoffset就是(0,480),也就是y偏移了480
contentInset是scrollview的contentview的顶点相对于scrollview的位置,例如你的contentInset= (0 ,100),那么你的contentview就是从scrollview的(0 ,100)开始显示
另外UITableView是UIScrollView的子类,它们在上述属性又有所不同,tabelview的contentsize是由它的下列方法共同实现的
- (NSInteger)numberOfSections;
- (NSInteger)numberOfRowsInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableViewheightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)tableView:(UITableView *)tableViewheightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableViewheightForFooterInSection:(NSInteger)section;
它会自动计算所有的高度和来做为它的contentsize的height.
例如你在delegate方法
- (NSInteger)tableView:(UITableView *)tableViewnumberOfRowsInSection:(NSInteger)section {
return100;
}
那么你的tabelview的contentsize就是(320, 4400)
属性 |
作用 |
CGPoint contentOffSet |
监控目前滚动的位置 |
CGSize contentSize |
滚动范围的大小 |
UIEdgeInsets contentInset |
视图在scrollView中的位置 |
id<UIScrollerViewDelegate> delegate |
设置协议 |
BOOL directionalLockEnabled |
指定控件是否只能在一个方向上滚动 |
BOOL bounces |
控制控件遇到边框是否反弹 |
BOOL alwaysBounceVertical |
控制垂直方向遇到边框是否反弹 |
BOOL alwaysBounceHorizontal |
控制水平方向遇到边框是否反弹 |
BOOL pagingEnabled |
控制控件是否整页翻动 |
BOOL scrollEnabled |
控制控件是否能滚动 |
BOOL showsHorizontalScrollIndicator |
控制是否显示水平方向的滚动条 |
BOOL showsVerticalScrollIndicator |
控制是否显示垂直方向的滚动条 |
UIEdgeInsets scrollIndicatorInsets |
指定滚动条在scrollerView中的位置 |
UIScrollViewIndicatorStyle indicatorStyle |
设定滚动条的样式 |
float decelerationRate |
改变scrollerView的减速点位置 |
BOOL tracking |
监控当前目标是否正在被跟踪 |
BOOL dragging |
监控当前目标是否正在被拖拽 |
BOOL decelerating |
监控当前目标是否正在减速 |
BOOL delaysContentTouches |
控制视图是否延时调用开始滚动的方法 |
BOOL canCancelContentTouches |
控制控件是否接触取消touch的事件 |
float minimumZoomScale |
缩小的最小比例 |
float maximumZoomScale |
放大的最大比例 |
float zoomScale |
设置变化比例 |
BOOL bouncesZoom |
控制缩放的时候是否会反弹 |
BOOL zooming |
判断控件的大小是否正在改变 |
BOOL zoomBouncing |
判断是否正在进行缩放反弹 |
BOOL scrollsToTop |
控制控件滚动到顶部 |