scrollView.h

scrollView.h

scrollView屬性

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

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

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

@property(nonatomic)         CGSize                       contentSize;                    // default CGSizeZero
contentSize是內(nèi)容大小,也就是可以滾動(dòng)的大小绍在,默認(rèn)是0门扇,沒(méi)有滾動(dòng)效果

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

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

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

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

directionalLockEnabled:是否鎖定某個(gè)特定方向的滾動(dòng)嫉嘀,默認(rèn)值為NO稼跳。設(shè)置為YES時(shí),一旦用戶向水平或豎直方向拽動(dòng)時(shí)吃沪,另一個(gè)方向的滾動(dòng)則被鎖定了。但是如果首次拽動(dòng)是斜著的什猖,那么則不會(huì)鎖定方向票彪。

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

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

bounces:描述的當(dāng)scrollview的顯示超過(guò)內(nèi)容區(qū)域的邊緣以及返回時(shí)谅畅,是否有彈性,默認(rèn)值為YES噪服。值為YES的時(shí)候毡泻,意味著到達(dá)contentSize所描繪的的邊界的時(shí)候,拖動(dòng)會(huì)產(chǎn)生彈性粘优。值為No的時(shí)候仇味,拖動(dòng)到達(dá)邊界時(shí)呻顽,會(huì)立即停止。所以丹墨,如果在上面的例子當(dāng)中廊遍,將bounces設(shè)置為NO時(shí),窗口中是不會(huì)顯示contentSize范圍外的內(nèi)容的贩挣。

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

alwaysBounceVertical:默認(rèn)值為NO,如果該值設(shè)為YES搪搏,并且bounces也設(shè)置為YES狭握,那么,即使設(shè)置的contentSize比scrollView的size小疯溺,那么也是可以拖動(dòng)的论颅。

@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并且邊界可以反彈囱嫩,即使邊界比較小恃疯,允許垂直拖動(dòng)

alwaysBounceHorizontal:默認(rèn)值為NO,如果該值設(shè)為YES墨闲,并且bounces也設(shè)置為YES今妄,那么,即使設(shè)置的contentSize比scrollView的size小鸳碧,那么也是可以拖動(dòng)的盾鳞。

@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并且邊界可以反彈瞻离,即使邊界比較小腾仅,允許橫向拖動(dòng)

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

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

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

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

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

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

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

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

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

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

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

indicatorStyle: 狀態(tài)條的風(fēng)格醉拓,默認(rèn)值為UIScrollViewIndicatorStyleDefault伟姐。除此之外,還有UIScrollViewIndicatorStyleBlack, UIScrollViewIndicatorStyleWhite兩種其他風(fēng)格亿卤》弑可以用來(lái)和環(huán)境配色。

@property(nonatomic)         UIScrollViewIndicatorStyle   indicatorStyle;                 // default is UIScrollViewIndicatorStyleDefault
滾動(dòng)條的樣式排吴,基本只是設(shè)置顏色秆乳,總共3個(gè)顏色:默認(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:是否推遲觸屏手勢(shì)處理珊肃,默認(rèn)值為YES荣刑。設(shè)置為YES的時(shí)候,系統(tǒng)在確定是否發(fā)生scroll事件之后伦乔,才會(huì)處理觸屏手勢(shì)嘶摊,否則,則會(huì)立即調(diào)用touchesShouldBegin:withEvent:inContentView:方法评矩。

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

方法

*1

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

*2

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

*3


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

/*
 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.

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


 */

狀態(tài)跟蹤

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

tracking: 只讀马僻,一旦用戶開(kāi)始觸摸視圖(也許還沒(méi)有開(kāi)始拖動(dòng)),該屬性值為YES

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

dragging: 只讀畜眨,當(dāng)用戶開(kāi)始拖動(dòng)(手指已經(jīng)在屏幕上滑動(dò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正在被拖動(dòng)泛鸟,返回YES(檢測(cè)當(dāng)前目標(biāo)是否正在被拖拽)

decelerate: 只讀蝠咆,當(dāng)用戶松開(kāi)手指,但視圖仍在滾動(dòng)時(shí)谈况,該值返回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)滾動(dòng)后勺美,手指放開(kāi)但是孩子啊繼續(xù)滾動(dòng)中。這個(gè)時(shí)候是YES碑韵,其他時(shí)候是NO(監(jiān)控當(dāng)前目標(biāo)是否正在減速)

其他設(shè)置

delaysContentTouches:是否推遲觸屏手勢(shì)處理赡茸,默認(rèn)值為YES。設(shè)置為YES的時(shí)候祝闻,系統(tǒng)在確定是否發(fā)生scroll事件之后占卧,才會(huì)處理觸屏手勢(shì),否則联喘,則會(huì)立即調(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的時(shí)候豁遭,用戶觸碰開(kāi)始叭喜,scrollView要延遲一會(huì),看看用戶是否有意圖滾動(dòng)蓖谢。加入滾動(dòng)了捂蕴,那么捕捉touch-down時(shí)間,否則就不捕捉闪幽。加入值是NO啥辨,當(dāng)用戶觸碰,scrollView會(huì)立即觸發(fā)(控制試圖是否延時(shí)調(diào)用開(kāi)始滾動(dòng)的方法)

@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的時(shí)候盯腌,用戶觸碰后溉知,然后在一定時(shí)間內(nèi)沒(méi)有移動(dòng),scrollView發(fā)送tracking events,然后用戶移動(dòng)手指足夠長(zhǎng)度觸發(fā)滾動(dòng)事件级乍,這個(gè)時(shí)候scrollView發(fā)送了touchesCancelled:withEvent:到subView舌劳,然后scrollView開(kāi)始滾動(dòng)。假如為NO卡者,scrollView發(fā)送tracking events后蒿囤,就算用戶移動(dòng)手指,scrollView也不會(huì)滾動(dòng)(控制控件是否接觸取消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;
// 開(kāi)始發(fā)送tracking message消息給subview的時(shí)候調(diào)用這個(gè)方法崇决,決定是否發(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)會(huì)根據(jù)縮放過(guò)程調(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: 描述在縮放超過(guò)縮放比例時(shí)契吉,是否bounce跳仿,默認(rèn)值為YES。如果值為NO捐晶,則達(dá)到最大或最小縮放比例時(shí)會(huì)立即停止縮放菲语。否則,產(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ū)別在于:這個(gè)效果反應(yīng)在縮放方面加入縮放超過(guò)最大縮放,那么會(huì)有反彈效果英支;假如是NO佩憾,則到達(dá)最大或者最小的時(shí)候立即停止

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

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

zoomBouncing:只讀妄帘,當(dāng)縮放超過(guò)最大或者最小范圍的時(shí)候,回彈到最大最小范圍的過(guò)程中把敢,該值返回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)容放大到最大或者縮小到最小的時(shí)候值是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:是否啟動(dòng)“滾動(dòng)至頂端”手勢(shì)修赞,默認(rèn)值為YES。當(dāng)用戶使用了“滾動(dòng)至頂端”手勢(shì)(輕擊狀態(tài)欄)時(shí),系統(tǒng)會(huì)要求離狀態(tài)欄最近的scrollView滾動(dòng)到頂端柏副,如果scrollToTop設(shè)置為NO勾邦,則該scrollView的delegate的scrollViewShouldScrollToTop:方法會(huì)返回NO,不會(huì)滾動(dòng)到頂端割择。否則眷篇,則會(huì)滾動(dòng)到頂端。滾動(dòng)到頂端之后荔泳,會(huì)給delegate發(fā)送scrollViewDidScrollToTop:消息蕉饼。需要注意的是,在iphone上玛歌,如果有多個(gè)scrollview的scrollToTop參數(shù)設(shè)置為YES的時(shí)候昧港,“滾動(dòng)至頂端”手勢(shì)會(huì)失效。

@property(nonatomic) BOOL  scrollsToTop __TVOS_PROHIBITED;          // default is YES.
是否支持滑動(dòng)到最頂端(點(diǎn)擊狀態(tài)條的時(shí)候)
// 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)拖動(dòng)發(fā)生時(shí)支子,鍵盤(pán)的消失模式创肥,默認(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)拖動(dòng)時(shí)鍵盤(pán)消失
UIScrollViewKeyboardDismissModeInteractive, // the keyboard follows the dragging touch off screen, and may be pulled upward again to cancel the dismiss 鍵盤(pán)跟隨拖動(dòng)觸摸屏,并可能再次向上拉值朋,取消消失
} NS_ENUM_AVAILABLE_IOS(7_0);


@protocol UIScrollViewDelegate<NSObject>

@optional

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

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

解釋

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

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

列:

//scrollView滾動(dòng)時(shí)篙骡,就調(diào)用該方法稽坤。任何offset值改變都調(diào)用該方法。即滾動(dòng)過(guò)程中糯俗,調(diào)用多次 
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

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

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


}

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

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

列:

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

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


}

*3scrollView開(kāi)始拖動(dòng)

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

解釋

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView; 
// 用戶開(kāi)始拖動(dòng) scroll view 的時(shí)候被調(diào)用淘正,可能需要一些時(shí)間和距離移動(dòng)之后才會(huì)觸發(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)開(kāi)始滾動(dòng)視圖時(shí),執(zhí)行該方法鸿吆。一次有效滑動(dòng)(開(kāi)始滑動(dòng)囤采,滑動(dòng)一小段距離,只要手指不松開(kāi)惩淳,只算一次滑動(dòng))蕉毯,只執(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é)束拖動(dòng)時(shí)兩個(gè)方向都沒(méi)有速度)時(shí)代虾,didEndDragging 中的 decelerate 為 NO进肯,即沒(méi)有減速過(guò)程,
//willBeginDecelerating 和 didEndDecelerating 也就不會(huì)被調(diào)用棉磨。反之江掩,
// 當(dāng) velocity 不為 CGPointZero 時(shí),scroll view 會(huì)以 velocity 為初速度乘瓤,
// 減速直到 targetContentOffset环形。

列:

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

    NSLog(@"scrollViewWillEndDragging");

}

*5scrollView結(jié)束拖動(dòng)

// scrollView結(jié)束拖動(dòng)
//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é)束拖動(dòng)后被調(diào)用,decelerate 為 YES 時(shí)蓄喇,
// 結(jié)束拖動(dòng)后會(huì)有減速過(guò)程发侵。注,在 didEndDragging 之后妆偏,如果有減速過(guò)程刃鳄,
// scroll view 的 dragging 并不會(huì)立即置為 NO,而是要等到減速結(jié)束之后钱骂,
// 所以這個(gè) dragging 屬性的實(shí)際語(yǔ)義更接近 scrolling叔锐。

列:

//結(jié)束拖動(dòng),手指離開(kāi)屏幕见秽,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;   // 減速動(dòng)畫(huà)開(kāi)始前被調(diào)用

列:

// 滑動(dòng)減速時(shí)調(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;      
// 減速動(dòng)畫(huà)結(jié)束時(shí)被調(diào)用解取,這里有一種特殊情況:當(dāng)一次減速動(dòng)畫(huà)尚未結(jié)束的時(shí)候再次 drag scroll view步责,
// didEndDecelerating 不會(huì)被調(diào)用,并且這時(shí) scroll view 的 dragging 和 decelerating 屬性都是 YES禀苦。
// 新的 dragging 如果有加速度蔓肯,那么 willBeginDecelerating 會(huì)再一次被調(diào)用,然后才是 didEndDecelerating振乏;
// 如果沒(méi)有加速度蔗包,雖然 willBeginDecelerating 不會(huì)被調(diào)用,但前一次留下的 didEndDecelerating 會(huì)被調(diào)用      

列:

// 滾動(dòng)視圖減速完成慧邮,滾動(dòng)將停止時(shí)调限,調(diào)用該方法邻储。一次有效滑動(dòng),只執(zhí)行一次旧噪。
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

    NSLog(@"scrollViewDidEndDecelerating");

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

}

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

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

列:

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

    NSLog(@"scrollViewDidEndScrollingAnimation");
    // 有效的動(dòng)畫(huà)方法為:
    //    - (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
告訴代理要縮放那個(gè)控件米母。 

列:

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

*10開(kāi)始縮放

// 開(kāi)始縮放
- (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縮放開(kāi)始的時(shí)候調(diào)用

列:

// 當(dāng)將要開(kāi)始縮放時(shí)毡琉,執(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縮放完畢的時(shí)候調(diào)用慧耍。

列:

// 當(dāng)縮放結(jié)束后,并且縮放大小回到minimumZoomScale與maximumZoomScale之間后(我們也許會(huì)超出縮放范圍)丐谋,調(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滾動(dòng)動(dòng)畫(huà)完成時(shí)調(diào)用吏饿。

列:

// 指示當(dāng)用戶點(diǎn)擊狀態(tài)欄后踪危,滾動(dòng)視圖是否能夠滾動(dòng)到頂部。需要設(shè)置滾動(dòng)視圖的屬性:_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)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末猪落,一起剝皮案震驚了整個(gè)濱河市贞远,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌许布,老刑警劉巖兴革,帶你破解...
    沈念sama閱讀 211,042評(píng)論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異蜜唾,居然都是意外死亡杂曲,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 89,996評(píng)論 2 384
  • 文/潘曉璐 我一進(jìn)店門(mén)袁余,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)擎勘,“玉大人,你說(shuō)我怎么就攤上這事颖榜∨锒” “怎么了煤裙?”我有些...
    開(kāi)封第一講書(shū)人閱讀 156,674評(píng)論 0 345
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)噪漾。 經(jīng)常有香客問(wèn)我硼砰,道長(zhǎng),這世上最難降的妖魔是什么欣硼? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,340評(píng)論 1 283
  • 正文 為了忘掉前任题翰,我火速辦了婚禮,結(jié)果婚禮上诈胜,老公的妹妹穿的比我還像新娘豹障。我一直安慰自己,他們只是感情好焦匈,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,404評(píng)論 5 384
  • 文/花漫 我一把揭開(kāi)白布血公。 她就那樣靜靜地躺著,像睡著了一般缓熟。 火紅的嫁衣襯著肌膚如雪累魔。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 49,749評(píng)論 1 289
  • 那天够滑,我揣著相機(jī)與錄音薛夜,去河邊找鬼。 笑死版述,一個(gè)胖子當(dāng)著我的面吹牛梯澜,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播渴析,決...
    沈念sama閱讀 38,902評(píng)論 3 405
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼晚伙,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了俭茧?” 一聲冷哼從身側(cè)響起咆疗,我...
    開(kāi)封第一講書(shū)人閱讀 37,662評(píng)論 0 266
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎母债,沒(méi)想到半個(gè)月后午磁,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,110評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡毡们,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,451評(píng)論 2 325
  • 正文 我和宋清朗相戀三年迅皇,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片衙熔。...
    茶點(diǎn)故事閱讀 38,577評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡登颓,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出红氯,到底是詐尸還是另有隱情框咙,我是刑警寧澤咕痛,帶...
    沈念sama閱讀 34,258評(píng)論 4 328
  • 正文 年R本政府宣布,位于F島的核電站喇嘱,受9級(jí)特大地震影響茉贡,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜者铜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,848評(píng)論 3 312
  • 文/蒙蒙 一块仆、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧王暗,春花似錦、人聲如沸庄敛。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,726評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)藻烤。三九已至绷雏,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間怖亭,已是汗流浹背涎显。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,952評(píng)論 1 264
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留兴猩,地道東北人期吓。 一個(gè)月前我還...
    沈念sama閱讀 46,271評(píng)論 2 360
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像倾芝,于是被迫代替她去往敵國(guó)和親讨勤。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,452評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容

  • 廢話不多說(shuō)晨另,直接上干貨 ---------------------------------------------...
    小小趙紙農(nóng)閱讀 3,343評(píng)論 0 15
  • UIScrollView是用來(lái)在屏幕上顯示那些在有限區(qū)域內(nèi)放不下的內(nèi)容潭千。例如,在手機(jī)屏幕上顯示內(nèi)容豐富的網(wǎng)頁(yè)或者很...
    勇敢的Springz81閱讀 64,805評(píng)論 12 85
  • 今天面試被鄙視了不過(guò)確實(shí)平時(shí)沒(méi)觀察到借尿!知其然知其所以然 UIScrollView是用來(lái)在屏幕上顯示那些在有限區(qū)域內(nèi)...
    貝勒老爺閱讀 12,985評(píng)論 0 15
  • 一綿春風(fēng)刨晴,綠意萌動(dòng),笨拙的雀兒壓彎了細(xì)枝路翻,余雪徑直摔在你的身邊狈癞,它卻不知歉意,啼叫著飛走了茂契。 那鳥(niǎo)兒有罪...
    一片蒲葦閱讀 231評(píng)論 0 0
  • 一轉(zhuǎn)眼就要來(lái)到2017了账嚎,公司也陸陸續(xù)續(xù)開(kāi)始年會(huì)莫瞬,家人儡蔓、朋友的聚餐也會(huì)接踵而至,緊接著春節(jié)等等疼邀,既是一個(gè)長(zhǎng)肉又是一...
    酒莊惠小九閱讀 1,368評(píng)論 0 0