一、UIScrollView简介
二、UIScrollView 属性
@property(nonatomic) CGSize contentSize;
2. 设置画布的偏移位置(画布的左上角与该 scrollView 对象的 frame 点的偏移,重合就是 0);默认是 CGSizeZero
@property(nonatomic) CGPoint contentOffset;
3. 内容视图在 UIScrollView 对象中的位置;默认为 UIEdgeInsetsZero
@property(nonatomic) UIEdgeInsets contentInset;
typedef struct UIEdgeInsets {
CGFloat top, left, bottom, right; // specify amount to inset (positive) for each of the edges. values can be negative to 'outset'
} UIEdgeInsets;
4. 代理对象
@property(nullable,nonatomic,weak)id<UIScrollViewDelegate> delegate;
5. 设置是否只能在一个方向上滚动;默认为 NO
@property(nonatomic,getter=isDirectionalLockEnabled)BOOL directionalLockEnabled;
6. 设置是否有反弹效果;默认为 YES
@property(nonatomic) BOOL bounces;
7. 设置垂直方向是否有反弹效果,必须在 bounces 为 YES 情况下才有效;默认为 NO
@property(nonatomic) BOOL alwaysBounceVertical;
8. 设置水平方向是否有反弹效果,必须在 bounces 为 YES 情况下才有效;默认为 NO
@property(nonatomic) BOOL alwaysBounceHorizontal;
9. 设置是否是整页翻动;默认为 NO
@property(nonatomic,getter=isPagingEnabled)BOOL pagingEnabled
10. 设置是否允许滑动;默认为 YES
@property(nonatomic,getter=isScrollEnabled)BOOL scrollEnabled;
11. 设置是否显示水平滚动条
@property(nonatomic) BOOL showsHorizontalScrollIndicator;
12. 设置是否显示垂直滚动条
@property(nonatomic) BOOL showsVerticalScrollIndicator;
13. 设置滚动条在滚动视图中的位置
@property(nonatomic) UIEdgeInsets scrollIndicatorInsets;
14. 设置滑动条的样式;默认是 UIScrollViewIndicatorStyleDefault
@property(nonatomic) UIScrollViewIndicatorStyle indicatorStyle;
typedef NS_ENUM(NSInteger, UIScrollViewIndicatorStyle) {
UIScrollViewIndicatorStyleDefault, // 黑色,边框为白色
UIScrollViewIndicatorStyleBlack, // 全黑色
UIScrollViewIndicatorStyleWhite // 全白色
};
@property(nonatomic) CGFloat decelerationRate
16. 设置 contentOffset 并设置动画
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;
17. 设置 contentOffset 并设置动画
- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated;
18. 用户触摸到 UIScrollView 对象或者开始拖动,返回 YES
@property(nonatomic,readonly,getter=isTracking) BOOL tracking;
19. 正在拖动中返回 YES
@property(nonatomic,readonly,getter=isDragging) BOOL dragging;
20. 没有拖动,但还在滑动,返回 YES
@property(nonatomic,readonly,getter=isDecelerating)BOOL decelerating;
21. 是否延迟调用 touchesBegan:withEvent:inContentView:;默认是 YES,
@property(nonatomic)BOOL delaysContentTouches;
22. 默认是 YES,如果是 NO,移动手指,将不能拖动
@property(nonatomic)BOOL canCancelContentTouches;
三、UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
2. 即将开始拖拽时调用
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
3. 即将停止拖拽
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inoutCGPoint *)targetContentOffset
4. 已经停止拖拽
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
5. 即将开始减速
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;
6. 已经停止减速,静止的一瞬间
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
7. 停止滚动
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView;