一、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;