UIScrollViewIndicatorStyle(滚动条样式):
UIScrollViewIndicatorStyleDefault, 默认
UIScrollViewIndicatorStyleBlack, 黑色
UIScrollViewIndicatorStyleWhite 白色
UIScrollViewKeyboardDismissMode(键盘消失模式):
UIScrollViewKeyboardDismissModeNone, 无效果
UIScrollViewKeyboardDismissModeOnDrag, 拖拽开始时消失
UIScrollViewKeyboardDismissModeInteractive, 从键盘上面点(scrollView未遮挡部分)向下滑动,键盘会跟着滑动;又往上滑动键盘也会跟着向上滑动
常用的属性:
@property(nonatomic) CGPoint contentOffset; 内容偏移量
@property(nonatomic) CGSize contentSize; 内容大小
@property(nonatomic) UIEdgeInsets contentInset; 内容上下左右区域的距离
@property(nonatomic,getter=isDirectionalLockEnabled)BOOL directionalLockEnabled; 水平或者垂直方向滚动锁(用户如果第一次在水平方向滚动,则不能在垂直方向滚动,反之亦然)
@property(nonatomic) BOOL bounces; 反弹效果开关
@property(nonatomic) BOOL alwaysBounceVertical; 垂直方向反弹效果开关
@property(nonatomic) BOOL alwaysBounceHorizontal; 水平方向反弹效果开关
@property(nonatomic,getter=isPagingEnabled)BOOL pagingEnabled__TVOS_PROHIBITED; 是否整页翻动
@property(nonatomic,getter=isScrollEnabled)BOOL scrollEnabled; 是否可以滚动
@property(nonatomic) BOOL showsHorizontalScrollIndicator; 显示水平滚动条
@property(nonatomic) BOOL showsVerticalScrollIndicator; 显示垂直滚动条
@property(nonatomic) UIEdgeInsets scrollIndicatorInsets; 滚动条位置
@property(nonatomic,readonly,getter=isTracking) BOOL tracking; 触摸后拖动前为YES,否则为NO
@property(nonatomic,readonly,getter=isDragging) BOOL dragging; 是否正在拖拽
@property(nonatomic,readonly,getter=isDecelerating)BOOL decelerating; 用户没有拖拽、但scrollview仍在滚动时为YES
以下两个属性表述比较复杂,参照 ch_soft 的表述
@property(nonatomic)BOOL delaysContentTouches;
当值是 YES 的时候,用户触碰开始,scroll view要延迟一会,看看是否用户有意图滚动。假如滚动了,那么捕捉 touch-down 事件,否则就不捕捉。假如值是NO,当用户触碰, scroll view 会立即触发 touchesShouldBegin:withEvent:inContentView:,默认是 YES
@property(nonatomic)BOOL canCancelContentTouches;
当值是 YES 的时候,用户触碰后,然后在一定时间内没有移动,scrollView 发送 tracking events,然后用户移动手指足够长度触发滚动事件,这个时候,scrollView 发送了 touchesCancelled:withEvent: 到 subview,然后 scrollView 开始滚动。假如值是 NO,scrollView 发送 tracking events 后,就算用户移动手指,scrollView 也不会滚动。
@property(nonatomic) CGFloat minimumZoomScale; 最小缩放比
@property(nonatomic) CGFloat maximumZoomScale; 最大缩放比
@property(nonatomic) CGFloat zoomScale NS_AVAILABLE_IOS(3_0); 缩放比
- (void)setZoomScale:(CGFloat)scale animated:(BOOL)animated NS_AVAILABLE_IOS(3_0); 设置缩放比
- (void)zoomToRect:(CGRect)rect animated:(BOOL)animated NS_AVAILABLE_IOS(3_0); 缩放到指定的大小
@property(nonatomic) BOOL bouncesZoom; 缩放反弹(缩放到限制值时反弹效果)
@property(nonatomic,readonly,getter=isZooming) BOOL zooming; 正在缩放
@property(nonatomic,readonly,getter=isZoomBouncing) BOOL zoomBouncing; 正在缩放反弹
@property(nonatomic) BOOL scrollsToTop __TVOS_PROHIBITED; 滚动到顶部
- (BOOL)touchesShouldBegin:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event inContentView:(UIView *)view; 是否接收touch事件
- (BOOL)touchesShouldCancelInContentView:(UIView *)view; 开始发送 tracking messages 消息给 subview 的时候调用这个方法,决定是否发送 tracking messages 消息到subview
- (void)flashScrollIndicators; 当滚动视图移动到前面时,应该调用此方法
UIScrollView协议:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView; scrollview滚动后,即offset发生变化时
- (void)scrollViewDidZoom:(UIScrollView *)scrollView NS_AVAILABLE_IOS(3_2); scrollview缩放后
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView; scrollview将要发生拖拽时
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0); scrollview将要结束拖拽时
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate; scrollview结束拖拽后
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView; 将要开始减速时(就是手指抬起后)
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView; 减速结束后
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView; // called when setContentOffset/scrollRectVisible:animated: finishes. not called if not animating
- (nullable UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView; // return a view that will be scaled. if delegate returns nil, nothing happens
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view NS_AVAILABLE_IOS(3_2); scrollview将要开始缩放时
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale; scrollview缩放结束后
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView; // return a yes if you want to scroll to the top. if not defined, assumes YES
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView; // called when scrolling animation finished. may be called immediately if already at top