iOS——UIScrollView

一、UIScrollView簡介

1. UIScrollView 對象適用於那些 尺寸大於屏幕的視圖,當某個視圖是 UIScrollView 對象的子視圖時,該 UIScrollView 對象會畫出該視圖的某塊矩形區域,當用戶拖動視圖時,UIScrollView 對象會改變該矩形所顯示的子視圖的區域

二、UIScrollView 屬性

1. 設置畫布大小,即能顯示某個子視圖的大小,通常爲子視圖的大小;默認爲 CGSizeZero

@property(nonatomicCGSize contentSize;


2. 設置畫布的偏移位置(畫布的左上角與該 scrollView 對象的 frame 點的偏移,重合就是 0);默認是 CGSizeZero

@property(nonatomicCGPoint contentOffset; 


3. 內容視圖在 UIScrollView 對象中的位置;默認爲 UIEdgeInsetsZero

@property(nonatomicUIEdgeInsets 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(nonatomicBOOL bounces; 


7. 設置垂直方向是否有反彈效果,必須在 bounces 爲 YES 情況下才有效;默認爲 NO

@property(nonatomicBOOL alwaysBounceVertical;


8. 設置水平方向是否有反彈效果,必須在 bounces 爲 YES 情況下才有效;默認爲 NO

@property(nonatomicBOOL alwaysBounceHorizontal;


9. 設置是否是整頁翻動;默認爲 NO

@property(nonatomic,getter=isPagingEnabled)BOOL pagingEnabled


10. 設置是否允許滑動;默認爲 YES

@property(nonatomic,getter=isScrollEnabled)BOOL scrollEnabled;


11. 設置是否顯示水平滾動條

@property(nonatomicBOOL showsHorizontalScrollIndicator;


12. 設置是否顯示垂直滾動條

@property(nonatomicBOOL showsVerticalScrollIndicator;


13. 設置滾動條在滾動視圖中的位置

@property(nonatomicUIEdgeInsets scrollIndicatorInsets;


14. 設置滑動條的樣式;默認是 UIScrollViewIndicatorStyleDefault

@property(nonatomicUIScrollViewIndicatorStyle indicatorStyle; 

typedef NS_ENUM(NSInteger, UIScrollViewIndicatorStyle) {
    UIScrollViewIndicatorStyleDefault,     // 黑色,邊框爲白色
    UIScrollViewIndicatorStyleBlack,       // 全黑色 
    UIScrollViewIndicatorStyleWhite        // 全白色
};


15. 滑動速率

@property(nonatomicCGFloat 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

1. 滾動時觸發

- (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;






發佈了31 篇原創文章 · 獲贊 0 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章