scrollView.h

scrollView.h

scrollView屬性

contentOffset: 描述了內(nèi)容視圖相對于scrollView窗口的位置(當(dāng)然是向上向左的偏移量咯)。默認(rèn)值是CGPointZero,也就是(0,0)。當(dāng)視圖被拖動時,系統(tǒng)會不斷修改該值。也可以通過setContentOffset:animated:方法讓圖片到達(dá)某個指定的位置。

@property(nonatomic)         CGPoint                      contentOffset;                  // default CGPointZero  在滾動視圖中,contentOffset屬性可以跟蹤UIScrollView的具體位置,你能夠自己獲取和設(shè)置它,contentOffset的值是你當(dāng)前可視內(nèi)容在滾動視圖上面偏移原來的左上角的偏移量

contentSize描述了有多大范圍的內(nèi)容需要使用scrollView的窗口來顯示,其默認(rèn)值為CGSizeZero,也就是一個寬和高都是0的范圍。

@property(nonatomic)         CGSize                       contentSize;                    // default CGSizeZero
contentSize是內(nèi)容大小,也就是可以滾動的大小,默認(rèn)是0,沒有滾動效果

contentInset: 表示scrollView的內(nèi)邊距,也就是內(nèi)容視圖邊緣和scrollView的邊緣的留空距離,默認(rèn)值是UIEdgeInsetsZero,也就是沒間距。這個屬性用的不多,通常在需要刷新內(nèi)容時才用得到。

@property(nonatomic)         UIEdgeInsets                 contentInset;                   // default UIEdgeInsetsZero. add additional scroll area around content contentInset增加你在contentSize中指定的內(nèi)容能夠滾動的上下左右區(qū)域的距離。

scrollView的委托對象,該委托對象必須實(shí)現(xiàn)UIScrollViewDelegate協(xié)議,這些方法會在合適的時候被調(diào)用。

@property(nullable,nonatomic,weak) id<UIScrollViewDelegate>        delegate;                       // default nil. weak reference

directionalLockEnabled:是否鎖定某個特定方向的滾動,默認(rèn)值為NO。設(shè)置為YES時,一旦用戶向水平或豎直方向拽動時,另一個方向的滾動則被鎖定了。但是如果首次拽動是斜著的,那么則不會鎖定方向。

@property(nonatomic,getter=isDirectionalLockEnabled) BOOL directionalLockEnabled;         // default NO. if YES, try to lock vertical or horizontal scrolling while dragging 默認(rèn)是NO,可以在垂直和水平方向同時運(yùn)動。當(dāng)值是YES時,假如一開始是垂直或者水平運(yùn)動,那么接下來會送定另外一個方向的滾動,加入一開始是對角方向移動,則不會禁止某個方向

scrollView的這種回彈機(jī)制,是可以設(shè)置的,相關(guān)的屬性

bounces:描述的當(dāng)scrollview的顯示超過內(nèi)容區(qū)域的邊緣以及返回時,是否有彈性,默認(rèn)值為YES。值為YES的時候,意味著到達(dá)contentSize所描繪的的邊界的時候,拖動會產(chǎn)生彈性。值為No的時候,拖動到達(dá)邊界時,會立即停止。所以,如果在上面的例子當(dāng)中,將bounces設(shè)置為NO時,窗口中是不會顯示contentSize范圍外的內(nèi)容的。

@property(nonatomic)         BOOL                         bounces;                        // default YES. if YES, bounces past edge of content and back again 默認(rèn)是YES,就是滾動超過邊界會反彈,有反彈回來的效果,如果是NO,那么滾動到達(dá)邊界會立即停止

alwaysBounceVertical:默認(rèn)值為NO,如果該值設(shè)為YES,并且bounces也設(shè)置為YES,那么,即使設(shè)置的contentSize比scrollView的size小,那么也是可以拖動的。

@property(nonatomic)         BOOL                         alwaysBounceVertical;           // default NO. if YES and bounces is YES, even if content is smaller than bounds, allow drag vertically
默認(rèn)是NO,如果是YES并且邊界可以反彈,即使邊界比較小,允許垂直拖動

alwaysBounceHorizontal:默認(rèn)值為NO,如果該值設(shè)為YES,并且bounces也設(shè)置為YES,那么,即使設(shè)置的contentSize比scrollView的size小,那么也是可以拖動的。

@property(nonatomic)         BOOL                         alwaysBounceHorizontal;         // default NO. if YES and bounces is YES, even if content is smaller than bounds, allow drag horizontally
默認(rèn)是NO,如果是YES并且邊界可以反彈,即使邊界比較小,允許橫向拖動

pagingEnabled:是否使用分頁機(jī)制,默認(rèn)值為NO。當(dāng)設(shè)置為YES時,會按照scrollView的寬度對內(nèi)容視圖進(jìn)行分頁。

@property(nonatomic,getter=isPagingEnabled) BOOL          pagingEnabled __TVOS_PROHIBITED;// default NO. if YES, stop on multiples of view bounds
當(dāng)值是YES會自動滾到視圖邊界的倍數(shù)上,默認(rèn)為NO(也就是是否整頁翻動)

scrollEnabled:視圖是否可被拖動,默認(rèn)值為YES。一旦該值設(shè)置為NO,則scrollView不再接受觸屏事件,會直接傳遞響應(yīng)鏈。

@property(nonatomic,getter=isScrollEnabled) BOOL          scrollEnabled;                  // default YES. turn off any dragging temporarily
默認(rèn)是YES,決定是否可以滾動

狀態(tài)條顯示indicatorStyle showsHorizontalScrollIndicator showsVerticalScrollIndicator scrollIndicatorInsets flashScrollIndicators

showsHorizontalScrollIndicator : 當(dāng)處于跟蹤狀態(tài)(tracking)時是否顯示水平狀態(tài)條,默認(rèn)值為YES。下一節(jié)說明什么是跟蹤狀態(tài)。

@property(nonatomic)         BOOL                         showsHorizontalScrollIndicator; // default YES. show indicator while we are tracking. fades out after isTracking 滾動時是否顯示水平滾動條

showsVerticalScrollIndicator : 當(dāng)處于跟蹤狀態(tài)(tracking)時是否顯示垂直狀態(tài)條,默認(rèn)值為YES。

@property(nonatomic)         BOOL                         showsVerticalScrollIndicator;   // default YES. show indicator while we are tracking. fades out after tracking  滾動時是否顯示垂直滾動條

scrollIndicatorInsets : 狀態(tài)條和scrollView邊距的距離(暫時還沒想明白為什么要有這個)。

@property(nonatomic)         UIEdgeInsets                 scrollIndicatorInsets;          // default is UIEdgeInsetsZero. adjust indicators inside of insets 設(shè)置滾動條的位置

indicatorStyle: 狀態(tài)條的風(fēng)格,默認(rèn)值為UIScrollViewIndicatorStyleDefault。除此之外,還有UIScrollViewIndicatorStyleBlack, UIScrollViewIndicatorStyleWhite兩種其他風(fēng)格??梢杂脕砗铜h(huán)境配色。

@property(nonatomic)         UIScrollViewIndicatorStyle   indicatorStyle;                 // default is UIScrollViewIndicatorStyleDefault
滾動條的樣式,基本只是設(shè)置顏色,總共3個顏色:默認(rèn)、黑、白

typedef NS_ENUM(NSInteger, UIScrollViewIndicatorStyle) {
UIScrollViewIndicatorStyleDefault, // black with white border. good against any background
黑與白邊,在任何背景下都很好
UIScrollViewIndicatorStyleBlack, // black only. smaller. good against a white background
只有黑色,小,在白色背景下良好
UIScrollViewIndicatorStyleWhite // white only. smaller. good against a black background
只有白色,小,在黑色背景下良好

};


其他設(shè)置

delaysContentTouches:是否推遲觸屏手勢處理,默認(rèn)值為YES。設(shè)置為YES的時候,系統(tǒng)在確定是否發(fā)生scroll事件之后,才會處理觸屏手勢,否則,則會立即調(diào)用touchesShouldBegin:withEvent:inContentView:方法。

@property(nonatomic)         CGFloat                      decelerationRate NS_AVAILABLE_IOS(3_0);
// 設(shè)置手指放開后的減速率

方法

*1

- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;  // animate at constant velocity to new offset
以恒定速度的動畫到新的偏移量

*2

- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated;         // scroll so rect is just visible (nearest edges). nothing if rect completely visible 
// 上面這兩個函數(shù)用來自動滾到想要的位置,此過程中設(shè)置有動畫效果,停止時,觸發(fā)該函數(shù)。當(dāng)animated為YES的時候有動畫效果

*3


- (void)flashScrollIndicators;             // displays the scroll indicators for a short time. This should be done whenever you bring the scroll view to front.
短時間內(nèi)顯示滾動條

/*
 Scrolling with no scroll bars is a bit complex. on touch down, we don't know if the user will want to scroll or track a subview like a control.
 on touch down, we start a timer and also look at any movement. if the time elapses without sufficient change in position, we start sending events to
 the hit view in the content subview. if the user then drags far enough, we switch back to dragging and cancel any tracking in the subview.
 the methods below are called by the scroll view and give subclasses override points to add in custom behaviour.
 you can remove the delay in delivery of touchesBegan:withEvent: to subviews by setting delaysContentTouches to NO.

沒有滾動條的滾動是一個有點(diǎn)復(fù)雜的。在觸摸結(jié)束后,我們不知道用戶將要滾動畫著跟蹤視圖像控制。
在接觸下來,我們開始一個計(jì)時器,也看任何運(yùn)動。如果沒有足夠的時間改變位置,我們開始向中觀的內(nèi)容試圖發(fā)送事件。如果用戶拖拽足夠遠(yuǎn),我們切換回拖和取消在子視圖的任何跟蹤。
下面的方法是由滾動視圖調(diào)用的,給子類重寫點(diǎn)添加自定義行為。
你可以刪除交貨延遲 touchesBegen:withEvent: 設(shè)置子視圖的delaysContentTouches


 */

狀態(tài)跟蹤

之前提到過跟蹤狀態(tài)(tracking)。相關(guān)的屬性有三個:tracking dragging decelerate,這三個屬性表明了當(dāng)前視圖的滾動狀態(tài)。

tracking: 只讀,一旦用戶開始觸摸視圖(也許還沒有開始拖動),該屬性值為YES

@property(nonatomic,readonly,getter=isTracking)     BOOL tracking;        // returns YES if user has touched. may not yet have started dragging 當(dāng)用戶touch后還沒有開始拖動的時候是YES,否則為NO

dragging: 只讀,當(dāng)用戶開始拖動(手指已經(jīng)在屏幕上滑動一段距離了),該屬性值為YES

@property(nonatomic,readonly,getter=isDragging)     BOOL dragging;        // returns YES if user has started scrolling. this may require some time and or distance to move to initiate dragging 如果scrollView正在被拖動,返回YES(檢測當(dāng)前目標(biāo)是否正在被拖拽)

decelerate: 只讀,當(dāng)用戶松開手指,但視圖仍在滾動時,該值返回YES

@property(nonatomic,readonly,getter=isDecelerating) BOOL decelerating;    // returns YES if user isn't dragging (touch up) but scroll view is still moving
當(dāng)滾動后,手指放開但是孩子啊繼續(xù)滾動中。這個時候是YES,其他時候是NO(監(jiān)控當(dāng)前目標(biāo)是否正在減速)

其他設(shè)置

delaysContentTouches:是否推遲觸屏手勢處理,默認(rèn)值為YES。設(shè)置為YES的時候,系統(tǒng)在確定是否發(fā)生scroll事件之后,才會處理觸屏手勢,否則,則會立即調(diào)用touchesShouldBegin:withEvent:inContentView:方法。

@property(nonatomic) BOOL delaysContentTouches;       // default is YES. if NO, we immediately call -touchesShouldBegin:withEvent:inContentView:. this has no effect on presses 默認(rèn)是YES,當(dāng)值是YES的時候,用戶觸碰開始,scrollView要延遲一會,看看用戶是否有意圖滾動。加入滾動了,那么捕捉touch-down時間,否則就不捕捉。加入值是NO,當(dāng)用戶觸碰,scrollView會立即觸發(fā)(控制試圖是否延時調(diào)用開始滾動的方法)

@property(nonatomic) BOOL canCancelContentTouches;    // default is YES. if NO, then once we start tracking, we don't try to drag if the touch moves. this has no effect on presses 當(dāng)值是YES的時候,用戶觸碰后,然后在一定時間內(nèi)沒有移動,scrollView發(fā)送tracking events,然后用戶移動手指足夠長度觸發(fā)滾動事件,這個時候scrollView發(fā)送了touchesCancelled:withEvent:到subView,然后scrollView開始滾動。假如為NO,scrollView發(fā)送tracking events后,就算用戶移動手指,scrollView也不會滾動(控制控件是否接觸取消touch的事件)

// override points for subclasses to control delivery of touch events to subviews of the scroll view
// called before touches are delivered to a subview of the scroll view. if it returns NO the touches will not be delivered to the subview
// this has no effect on presses
// default returns YES 默認(rèn)返回是

方法

*1

- (BOOL)touchesShouldBegin:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event inContentView:(UIView *)view;
// called before scrolling begins if touches have already been delivered to a subview of the scroll view. if it returns NO the touches will continue to be delivered to the subview and scrolling will not occur
// not called if canCancelContentTouches is NO. default returns YES if view isn't a UIControl
// this has no effect on presses

*2

- (BOOL)touchesShouldCancelInContentView:(UIView *)view;
// 開始發(fā)送tracking message消息給subview的時候調(diào)用這個方法,決定是否發(fā)送tracking message消息給subView,假如返回NO,發(fā)送,YES則不發(fā)送




/*
 the following properties and methods are for zooming. as the user tracks with two fingers, we adjust the offset and the scale of the content. When the gesture ends, you should update the content
 as necessary. Note that the gesture can end and a finger could still be down. While the gesture is in progress, we do not send any tracking calls to the subview.
 the delegate must implement both viewForZoomingInScrollView: and scrollViewDidEndZooming:withView:atScale: in order for zooming to work and the max/min zoom scale must be different
 note that we are not scaling the actual scroll view but the 'content view' returned by the delegate. the delegate must return a subview, not the scroll view itself, from viewForZoomingInScrollview:
 */

縮放

minimumZoomScale: 最小放大比例,默認(rèn)值為1,不得大于maxmumZoomScale

@property(nonatomic) CGFloat minimumZoomScale;     // default is 1.0
表示能縮最小的倍數(shù)

maximumZoomScale: 最大放大比例,默認(rèn)值為1,不得小于minimumZoomScale

@property(nonatomic) CGFloat maximumZoomScale;     // default is 1.0. must be > minimum zoom scale to enable zooming 表示能放最大的倍數(shù)

zoomScale: 當(dāng)前的縮放比例。系統(tǒng)會根據(jù)縮放過程調(diào)整此值。

@property(nonatomic) CGFloat zoomScale NS_AVAILABLE_IOS(3_0);            // default is 1.0

方法

setZoomScale:animated:: 程序設(shè)置縮放大小。
- (void)setZoomScale:(CGFloat)scale animated:(BOOL)animated NS_AVAILABLE_IOS(3_0);
zoomToRect:animated: 將內(nèi)容視圖縮放到指定的Rect中。
- (void)zoomToRect:(CGRect)rect animated:(BOOL)animated NS_AVAILABLE_IOS(3_0);

bouncesZoom: 描述在縮放超過縮放比例時,是否bounce,默認(rèn)值為YES。如果值為NO,則達(dá)到最大或最小縮放比例時會立即停止縮放。否則,產(chǎn)生彈簧效果。


@property(nonatomic) BOOL  bouncesZoom;          // default is YES. if set, user can go past min/max zoom while gesturing and the zoom will animate to the min/max value at gesture end 和bounces類似,區(qū)別在于:這個效果反應(yīng)在縮放方面加入縮放超過最大縮放,那么會有反彈效果;假如是NO,則到達(dá)最大或者最小的時候立即停止

zooming: 只讀,用戶是否正在進(jìn)行縮放手勢

@property(nonatomic,readonly,getter=isZooming)       BOOL zooming;       // returns YES if user in zoom gesture
當(dāng)正在縮放的時候是YES,否則是NO

zoomBouncing:只讀,當(dāng)縮放超過最大或者最小范圍的時候,回彈到最大最小范圍的過程中,該值返回YES。

@property(nonatomic,readonly,getter=isZoomBouncing)  BOOL zoomBouncing;  // returns YES if we are in the middle of zooming back to the min/max value 當(dāng)內(nèi)容放大到最大或者縮小到最小的時候值是YES,否則是NO

// When the user taps the status bar, the scroll view beneath the touch which is closest to the status bar will be scrolled to top, but only if its `scrollsToTop` property is YES, its delegate does not return NO from `shouldScrollViewScrollToTop`, and it is not already at the top.
// On iPhone, we execute this gesture only if there's one on-screen scroll view with `scrollsToTop` == YES. If more than one is found, none will be scrolled.

scrollToTop:是否啟動“滾動至頂端”手勢,默認(rèn)值為YES。當(dāng)用戶使用了“滾動至頂端”手勢(輕擊狀態(tài)欄)時,系統(tǒng)會要求離狀態(tài)欄最近的scrollView滾動到頂端,如果scrollToTop設(shè)置為NO,則該scrollView的delegate的scrollViewShouldScrollToTop:方法會返回NO,不會滾動到頂端。否則,則會滾動到頂端。滾動到頂端之后,會給delegate發(fā)送scrollViewDidScrollToTop:消息。需要注意的是,在iphone上,如果有多個scrollview的scrollToTop參數(shù)設(shè)置為YES的時候,“滾動至頂端”手勢會失效。

@property(nonatomic) BOOL  scrollsToTop __TVOS_PROHIBITED;          // default is YES.
是否支持滑動到最頂端(點(diǎn)擊狀態(tài)條的時候)
// Use these accessors to configure the scroll view's built-in gesture recognizers.
// Do not change the gestures' delegates or override the getters for these properties.

panGestureRecognizer

@property(nonatomic, readonly) UIPanGestureRecognizer *panGestureRecognizer NS_AVAILABLE_IOS(5_0);
// `pinchGestureRecognizer` will return nil when zooming is disabled.

pinchGestureRecognizer

@property(nullable, nonatomic, readonly) UIPinchGestureRecognizer *pinchGestureRecognizer NS_AVAILABLE_IOS(5_0);
// `directionalPressGestureRecognizer` is disabled by default, but can be enabled to perform scrolling in response to up / down / left / right arrow button presses directly, instead of scrolling indirectly in response to focus updates.

directionalPressGestureRecognizer

@property(nonatomic, readonly) UIGestureRecognizer *directionalPressGestureRecognizer UIKIT_
AVAILABLE_TVOS_ONLY(9_0);

keyboardDismissMode: 當(dāng)拖動發(fā)生時,鍵盤的消失模式,默認(rèn)值是不消失

@property(nonatomic) UIScrollViewKeyboardDismissMode keyboardDismissMode NS_AVAILABLE_IOS(7_0); // default is UIScrollViewKeyboardDismissModeNone

typedef NS_ENUM(NSInteger, UIScrollViewKeyboardDismissMode) {
UIScrollViewKeyboardDismissModeNone,
UIScrollViewKeyboardDismissModeOnDrag, // dismisses the keyboard when a drag begins
當(dāng)拖動時鍵盤消失
UIScrollViewKeyboardDismissModeInteractive, // the keyboard follows the dragging touch off screen, and may be pulled upward again to cancel the dismiss 鍵盤跟隨拖動觸摸屏,并可能再次向上拉,取消消失
} NS_ENUM_AVAILABLE_IOS(7_0);


@protocol UIScrollViewDelegate<NSObject>

@optional

*1scrollView已經(jīng)滑動

// scrollView已經(jīng)滑動
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;                                               // any offset changes

解釋

- (void)scrollViewDidScroll:(UIScrollView *)scrollView; 
// any offset changes 只要scrollView的content 這個方法在任何方式觸發(fā) contentOffset 
// 變化的時候都會被調(diào)用(包括用戶拖動,減速過程,直接通過代碼設(shè)置等),可以用于監(jiān)控 contentOffset 
// 的變化,并根據(jù)當(dāng)前的 contentOffset 對其他 view 做出隨動調(diào)整。

// called on start of dragging (may require some time and or distance to move)

列:

//scrollView滾動時,就調(diào)用該方法。任何offset值改變都調(diào)用該方法。即滾動過程中,調(diào)用多次 
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

    NSLog(@"scrollViewDidScroll");
    CGPoint point=scrollView.contentOffset;
    NSLog(@"%f,%f",point.x,point.y);
    // 從中可以讀取contentOffset屬性以確定其滾動到的位置。

    // 注意:當(dāng)ContentSize屬性小于Frame時,將不會出發(fā)滾動


}

*2視圖已經(jīng)放大或者縮小

// 視圖已經(jīng)放大或者縮小
- (void)scrollViewDidZoom:(UIScrollView *)scrollView NS_AVAILABLE_IOS(3_2); // any zoom scale changes

列:

// 當(dāng)scrollView縮放時,調(diào)用該方法。在縮放過程中,回多次調(diào)用
- (void)scrollViewDidZoom:(UIScrollView *)scrollView{

    NSLog(@"scrollViewDidScroll");
    float value=scrollView.zoomScale;
    NSLog(@"%f",value);


}

*3scrollView開始拖動

// scrollView開始拖動
called on start of dragging (may require some time and or distance to move)
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView; 

解釋

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView; 
// 用戶開始拖動 scroll view 的時候被調(diào)用,可能需要一些時間和距離移動之后才會觸發(fā)。

// called on finger up if the user dragged. velocity is in points/millisecond. 
// targetContentOffset may be changed to adjust where the scroll view comes to rest

列:

// 當(dāng)開始滾動視圖時,執(zhí)行該方法。一次有效滑動(開始滑動,滑動一小段距離,只要手指不松開,只算一次滑動),只執(zhí)行一次。
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{

    NSLog(@"scrollViewWillBeginDragging");

}

*4scrollView即將停止拖拽

// scrollView即將停止拖拽
//called on finger up if the user dragged. velocity is in points/millisecond. targetContentOffset may be changed to adjust where the scroll view comes to rest
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0);

解釋:

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0);
// 在 didEndDragging 前被調(diào)用,當(dāng) willEndDragging 方法中 velocity 為 CGPointZero
//(結(jié)束拖動時兩個方向都沒有速度)時,didEndDragging 中的 decelerate 為 NO,即沒有減速過程,
//willBeginDecelerating 和 didEndDecelerating 也就不會被調(diào)用。反之,
// 當(dāng) velocity 不為 CGPointZero 時,scroll view 會以 velocity 為初速度,
// 減速直到 targetContentOffset。

列:

// 滑動scrollView,并且手指離開時執(zhí)行。一次有效滑動,只執(zhí)行一次。
// 當(dāng)pagingEnabled屬性為YES時,不調(diào)用,該方法
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{

    NSLog(@"scrollViewWillEndDragging");

}

*5scrollView結(jié)束拖動

// scrollView結(jié)束拖動
//called on finger up if the user dragged. decelerate is true if it will continue moving afterwards
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;

解釋:

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
// 在用戶結(jié)束拖動后被調(diào)用,decelerate 為 YES 時,
// 結(jié)束拖動后會有減速過程。注,在 didEndDragging 之后,如果有減速過程,
// scroll view 的 dragging 并不會立即置為 NO,而是要等到減速結(jié)束之后,
// 所以這個 dragging 屬性的實(shí)際語義更接近 scrolling。

列:

//結(jié)束拖動,手指離開屏幕,decelerate(是否是減速狀態(tài))
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
     
//    decelerate == YES?NSLog(@"減速"):NSLog(@"停止");
}

*6scrollView即將減速完成

// scrollView即將減速完成
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;   // called on finger up as we are moving

解釋:

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;   // 減速動畫開始前被調(diào)用

列:

// 滑動減速時調(diào)用該方法。
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{

    NSLog(@"scrollViewWillBeginDecelerating");
    // 該方法在scrollViewDidEndDragging方法之后。


}

*7scrollView減速完成

// scrollView減速完成
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;      // called when scroll view grinds to a halt

解釋:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;      
// 減速動畫結(jié)束時被調(diào)用,這里有一種特殊情況:當(dāng)一次減速動畫尚未結(jié)束的時候再次 drag scroll view,
// didEndDecelerating 不會被調(diào)用,并且這時 scroll view 的 dragging 和 decelerating 屬性都是 YES。
// 新的 dragging 如果有加速度,那么 willBeginDecelerating 會再一次被調(diào)用,然后才是 didEndDecelerating;
// 如果沒有加速度,雖然 willBeginDecelerating 不會被調(diào)用,但前一次留下的 didEndDecelerating 會被調(diào)用      

列:

// 滾動視圖減速完成,滾動將停止時,調(diào)用該方法。一次有效滑動,只執(zhí)行一次。
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

    NSLog(@"scrollViewDidEndDecelerating");

    [_scrollView setContentOffset:CGPointMake(0, 500) animated:YES];

}

*8scrollView結(jié)束減速并且必須有動畫效果才會觸發(fā)(必須要有動畫效果)

// scrollView結(jié)束減速并且必須有動畫效果才會觸發(fā)(必須要有動畫效果)
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView; // called when setContentOffset/scrollRectVisible:animated: finishes. not called if not animating

列:

// 當(dāng)滾動視圖動畫完成后,調(diào)用該方法,如果沒有動畫,那么該方法將不被調(diào)用
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{

    NSLog(@"scrollViewDidEndScrollingAnimation");
    // 有效的動畫方法為:
    //    - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated 方法
    //    - (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated 方法


}

*9返回縮放后的試圖,但只能返回scrollView(內(nèi)容)上的子視圖

// 返回縮放后的試圖,但只能返回scrollView(內(nèi)容)上的子視圖
- (nullable UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;     // return a view that will be scaled. if delegate returns nil, nothing happens

解釋:

- (nullable UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;     
// return a view that will be scaled. if delegate returns nil, nothing happens
告訴代理要縮放那個控件。 

列:

//設(shè)置放大縮小的視圖,要是uiscrollview的subview
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;   
{
   NSLog(@"viewForZoomingInScrollView");
    return viewA;
}

*10開始縮放

// 開始縮放
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view NS_AVAILABLE_IOS(3_2); // called before the scroll view begins zooming its content

解釋:

- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view NS_AVAILABLE_IOS(3_2); 
// called before the scroll view begins zooming its content縮放開始的時候調(diào)用

列:

// 當(dāng)將要開始縮放時,執(zhí)行該方法。一次有效縮放,就只執(zhí)行一次。
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view{

    NSLog(@"scrollViewWillBeginZooming");

}

*11結(jié)束縮放

// 結(jié)束縮放

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale; // scale between minimum and maximum. called after any 'bounce' animations

解釋:

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale; 
// scale between minimum and maximum. called after any 'bounce' animations縮放完畢的時候調(diào)用。

列:

// 當(dāng)縮放結(jié)束后,并且縮放大小回到minimumZoomScale與maximumZoomScale之間后(我們也許會超出縮放范圍),調(diào)用該方法。
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale{

    NSLog(@"scrollViewDidEndZooming");

}

*12點(diǎn)擊狀態(tài)欄,調(diào)用此方法,此方法能實(shí)現(xiàn)的前提是scrollToTop的屬性是YES

// 點(diǎn)擊狀態(tài)欄,調(diào)用此方法,此方法能實(shí)現(xiàn)的前提是scrollToTop的屬性是YES
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView;   // return a yes if you want to scroll to the top. if not defined, assumes YES

解釋:

- (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滾動動畫完成時調(diào)用。

列:

// 指示當(dāng)用戶點(diǎn)擊狀態(tài)欄后,滾動視圖是否能夠滾動到頂部。需要設(shè)置滾動視圖的屬性:_scrollView.scrollsToTop=YES;
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView{

    return YES;


}
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView;   
{
    NSLog(@"scrollViewShouldScrollToTop");
   return YES;
}

*13scrollView已經(jīng)回到頂部了

// scrollView已經(jīng)回到頂部了
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView;      // called when scrolling animation finished. may be called immediately if already at top
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容