UIScrollView

一、簡介

<<繼承關(guān)系:UIScrollView --> UIView?-->UIResponder-->NSObject

<<是UITableView和UITextView等UIKit類的父類

<<UIScrollView這個類(也就是滾動視圖)最住,可以讓我們展示比window尺寸大的內(nèi)容侨糟。用戶可以通過手勢來實現(xiàn)視圖的滾動和縮放。

格式為

1--> 設(shè)置滾動條樣式(屬性的作用)

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

};(如果屬性有枚舉類型的話回季,這里會有枚舉類型說明)

scrollView.indicatorStyle?=?UIScrollViewIndicatorStyleDefault;??(這是具體的例子)

@property(nonatomic) UIScrollViewIndicatorStyle indicatorStyle; // default is UIScrollViewIndicatorStyleDefault(這是屬性的說明)

二家制、UIScrollView的內(nèi)容視圖屬性(屬性的順序與蘋果API一致)

1-->設(shè)置偏移量

scrollView.contentOffset = CGPointMake(314,200);

@property(nonatomic) CGPoint contentOffset; // 默認為 CGPointZero

2-->設(shè)置UIScrollView的內(nèi)容視圖的尺寸

scrollView.contentSize =CGSizeMake(314*3,500);//非常重要,這是UIScrollView的內(nèi)容視圖的尺寸泡一,通常contentSize大于UIScrollView的frame

@property(nonatomic) CGSize contentSize; // 默認為CGSizeZero

3颤殴、設(shè)置內(nèi)容的邊緣

scrollView.contentInset =UIEdgeInsetsMake(0,50,50,0);

@property(nonatomic) UIEdgeInsets contentInset; //默認UIEdgeInsetsZero。在內(nèi)容周圍添加額外的滾動區(qū)域鼻忠。

4涵但、獲得要繪制內(nèi)容的調(diào)整區(qū)域

UIEdgeInsets edge= self.scrollView.adjustedContentInset;

@property(nonatomic, readonly) UIEdgeInsets adjustedContentInset API_AVAILABLE(ios(11.0),tvos(11.0));

參見:你可能需要為你的 App 適配 iOS 11

5、感知adjustedContentInset的變化,觸發(fā)的方法

//重寫方法

- (void)adjustedContentInsetDidChange

{

[super adjustedContentInsetDidChange];


//執(zhí)行操作...

}

- (void)adjustedContentInsetDidChange API_AVAILABLE(ios(11.0),tvos(11.0)) NS_REQUIRES_SUPER;//UIScrollViewDelegate中的scrollViewDidChangeAdjustedContentInset方法同樣能實現(xiàn)

6、設(shè)置UIScrollView的調(diào)整行為

typedef NS_ENUM(NSInteger, UIScrollViewContentInsetAdjustmentBehavior) {

? ? UIScrollViewContentInsetAdjustmentAutomatic, //和scrollableAxes一樣,scrollView會自動計算和適應頂部和底部的內(nèi)邊距并且在scrollView?不可滾動時,也會設(shè)置內(nèi)邊距.

? ? UIScrollViewContentInsetAdjustmentScrollableAxes, //自動計算內(nèi)邊距.

? ? UIScrollViewContentInsetAdjustmentNever, //不計算內(nèi)邊距

? ? UIScrollViewContentInsetAdjustmentAlways, //根據(jù)safeAreaInsets 計算內(nèi)邊距

} API_AVAILABLE(ios(11.0),tvos(11.0));

if(@available(iOS11.0, *)) {

self.tableView.contentInsetAdjustmentBehavior =UIScrollViewContentInsetAdjustmentNever;

}else{

self.automaticallyAdjustsScrollViewInsets =NO;

}

@property(nonatomic) UIScrollViewContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior API_AVAILABLE(ios(11.0),tvos(11.0));//默認?UIScrollViewContentInsetAdjustmentAutomatic.

7矮瘟、描述內(nèi)容布局

? if (@available(iOS 11.0, *)) {

? ? ? ? UILayoutGuide *guide=self.scrollView.contentLayoutGuide;

? ? } else {

? ? }

@property(nonatomic,readonly,strong) UILayoutGuide *contentLayoutGuide API_AVAILABLE(ios(11.0),tvos(11.0));

8瞳脓、整體布局信息

if (@available(iOS 11.0, *)) {

? ? ? ? UILayoutGuide *guide=self.scrollView.frameLayoutGuide;

? ? } else {

? ? }

@property(nonatomic,readonly,strong) UILayoutGuide *frameLayoutGuide API_AVAILABLE(ios(11.0),tvos(11.0));

9、設(shè)置UIScrollView的代理

scrollView.delegate=self;

@property(nullable,nonatomic,weak) id <UIScrollViewDelegate>delegate; //默認為nil. 弱引用

10澈侠、設(shè)置UIScrollView是否單方向運動

scrollView.directionalLockEnabled =YES;

@property(nonatomic,getter=isDirectionalLockEnabled) BOOL directionalLockEnabled; // 默認 NO

11劫侧、設(shè)置UIScrollView是否反彈

scrollView.bounces =NO;

@property(nonatomic) BOOL bounces; //默認的YES。如果是YES哨啃,從內(nèi)容的邊緣反彈回來

12烧栋、設(shè)置控制垂直方向遇到邊框是否反彈

? ?scrollView.alwaysBounceVertical = NO;//控制垂直方向遇到邊框是否反彈@property(nonatomic) BOOL alwaysBounceVertical; //默認是NO。如果YES和bounces是YES拳球,即使內(nèi)容小于界限劲弦,允許垂直拖動。

13醇坝、設(shè)置控制水平遇到邊框是否反彈

? ? myScrollView.alwaysBounceHorizontal = NO;//控制水平遇到邊框是否反彈

@property(nonatomic) BOOL alwaysBounceHorizontal; // 默認是NO.如果YES和bounces是YES邑跪,即使內(nèi)容小于界限,允許水平拖動呼猪。

14画畅、設(shè)置是否翻頁

? ? myScrollView.pagingEnabled = NO; //是否翻頁

@property(nonatomic,getter=isPagingEnabled) BOOL pagingEnabled __TVOS_PROHIBITED;//默認是NO。如果是宋距,請停在視圖邊界的倍數(shù)上轴踱。

15、設(shè)置控制控件是否能滾動

? ? myScrollView.scrollEnabled = YES;//控制控件是否能滾動

@property(nonatomic,getter=isScrollEnabled) BOOL scrollEnabled; // 默認是YES谚赎。關(guān)閉任何拖拽淫僻。

16、設(shè)置垂直方向的滾動指示

? ? myScrollView.showsVerticalScrollIndicator =YES; //垂直方向的滾動指示

@property(nonatomic) BOOL showsVerticalScrollIndicator;//默認是YES

17壶唤、設(shè)置水平方向的滾動指示

?myScrollView.showsHorizontalScrollIndicator = NO;//水平方向的滾動指示

@property(nonatomic) BOOL showsVerticalScrollIndicator; //默認是YES

18雳灵、表示滾動指示器從封閉滾動視圖中被嵌入的距離

UIEdgeInsets e = UIEdgeInsetsMake(0, 0, keyboardBounds.size.height, 0);

[[self tableView] setScrollIndicatorInsets:e];

@property(nonatomic) UIEdgeInsets scrollIndicatorInsets; // 默認為UIEdgeInsetsZero.?

19、設(shè)置滾動控制器的風格

typedefNS_ENUM(NSInteger,?UIScrollViewIndicatorStyle)?{

????UIScrollViewIndicatorStyleDefault,?????//默認

????UIScrollViewIndicatorStyleBlack,???????//黑色風格

????UIScrollViewIndicatorStyleWhite????????//白色風格

};

scrollView .indicatorStyle=UIScrollViewIndicatorStyleDefault;

@property(nonatomic) UIScrollViewIndicatorStyle indicatorStyle; // 默認是 UIScrollViewIndicatorStyleDefault

20闸盔、設(shè)置滑動速度

? scrollView .decelerationRate=3;//浮點數(shù)悯辙,規(guī)定用戶提起手指后的滾動減速速率

@property(nonatomic) CGFloat decelerationRate NS_AVAILABLE_IOS(3_0);//你的應用程序可以使用UIScrollViewDecelerationRateNormal和UIScrollViewDecelerationRateFast常量作為引用點以獲得一個合理的減速速率。

21迎吵、設(shè)置滾動視圖內(nèi)容的偏移量躲撰,可以帶動畫效果

[scrollView setContentOffset:CGPointMake(_pageSize.width * self.page, 0) animated:NO];

- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated; // animate at constant velocity to new offset//

contentOffset,

內(nèi)容視圖原點的偏移點(以點的形式表示)击费。

animated拢蛋,

若YES,用一個恒定的速度以動畫形式移動到新的偏移處蔫巩;NO則立即移動

22谆棱、設(shè)置滾動視圖滾動到某個可見區(qū)域瞬铸,可以帶動畫效果

[scrollView?scrollRectToVisible:CGRectMake(0,?0,?1,?1)?animated:YES];//scrollView滾動到頂部

- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated; //rect,定義內(nèi)容視圖區(qū)域的矩形础锐。animated,若滾動應被動畫化則傳入YES荧缘,否則為NO皆警。

該方法滾動內(nèi)容視圖以使rect中定義的區(qū)域可以剛好顯示在滾動視圖中。若區(qū)域已經(jīng)是可見的截粗,該方法什么也不做信姓。

23、顯示一個短暫的滾動指示器

[scrollView flashScrollIndicators];//建議在scrollView展示給用戶時調(diào)用一下,以提醒用戶該處可滑動

- (void)flashScrollIndicators; // displays the scroll indicators for a short time. This should be done whenever you bring the scroll view to front.

24绸罗、獲取用戶是否觸及視圖內(nèi)容

BOOL isTracking=[scrollView isTracking];//只讀屬性

@property(nonatomic,readonly,getter=isTracking) BOOL tracking; //若用戶已觸摸內(nèi)容視圖但可以還示開始拖動時該屬性值為YES意推。

25、表明用戶是否開始滾動內(nèi)容

?BOOL dragging=[scrollView dragging];//只讀屬性

@property(nonatomic,readonly,getter=isDragging) BOOL dragging; //該屬性持有的值可能需要滾動一段時間或距離才會被設(shè)定成YES

26珊蟀、獲取視圖是否開始減速(用戶停止拖動但視圖仍在滾動)

BOOL?decelerating=[scrollView?decelerating];//只讀屬性

@property(nonatomic,readonly,getter=isDecelerating)?BOOL?decelerating; //若用戶已不再拖拽內(nèi)容但滾動還在發(fā)生時返回YES菊值。

27、設(shè)置視圖是否延遲處理觸摸事件

BOOL?delaysContentTouches=[scrollView?delaysContentTouches];

@property(nonatomic)BOOL delaysContentTouches;?//規(guī)定滾動視圖是否延遲處理觸摸下壓手勢育灸,若該屬性值為YES腻窒,滾動視圖會延遲處理下壓手勢直到可以確定該操作的意圖是否是滾動。若值為NO磅崭,滾動視圖會立即調(diào)用touchesShoudBegin:withEvent:inContentView:儿子。默認值為YES。

28砸喻、設(shè)置控制觸摸內(nèi)容視圖時是否總是導致跟蹤

_scrollView.canCancelContentTouches=YES;

@property(nonatomic) BOOL canCancelContentTouches;//控制觸摸內(nèi)容視圖時是否總是導致跟蹤柔逼。若該屬性的值為YES,內(nèi)容中的視圖會開始跟蹤觸摸的手指割岛,若用戶拖拽手指到足以滾動的距離愉适,視圖會收到touchesCancelled:withEvent:信息,而滾動視圖會作為一個滾動事件處理這次觸摸癣漆。若該屬性的值為NO儡毕,滾動視圖在內(nèi)容視圖開始跟蹤時將無視手指移動,不進行滾動扑媚。默認值為YES腰湾。

29、在觸摸事件開始相應前調(diào)用

- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view{

?????return YES;

}//?在UIScrollView的子類中重寫該方法,用于返回是否將事件傳遞給對應的子視圖,默認返回YES,如果返回NO,該事件不會傳遞給對應的子視圖

- (BOOL)touchesShouldBegin:(NSSet*)touches withEvent:(UIEvent*)event inContentView:(UIView*)view;//返回yes?-?將觸摸事件傳遞給相應的subView;?返回no?-?直接滾動scrollView疆股,不傳遞觸摸事件到subView?

30费坊、當設(shè)置canCancelContentTouches=YES時,觸摸事件響應前會調(diào)用該方法

-(BOOL)touchesShouldCancelInContentView:(UIView*)view{

if([view isKindOfClass:[UIButtonclass]]) {

returnYES;?

?}

return[super touchesShouldCancelInContentView:view];

}

- (BOOL)touchesShouldCancelInContentView:(UIView *)view;在UIScrollView的子類中重寫該方法,用于返回是否取消已經(jīng)傳遞給子視圖的事件,默認當子視圖是UIControl時返回NO,否則返回YES(注: 該方法被調(diào)用的前提是canCancelContentTouches = YES)

參見:iOS實現(xiàn)ScrollView中子控件(Button,自定義View)的觸摸事件響應

四旬痹、UIScrollView的Zoom屬性

1-->設(shè)置 最小縮放比例

?scrollView.minimumZoomScale=0.5;

@property(nonatomic) CGFloat minimumZoomScale; // 默認是1.0

2-->設(shè)置?最大縮放比例

?scrollView.maximumZoomScale=1.5;//必須大于minimumZoomScale才能正常工作

@property(nonatomic) CGFloat maximumZoomScale; // 默認是1.0

3附井、設(shè)置縮放比例

scrollView.zoomScale =0.8;

@property(nonatomic) CGFloat zoomScale NS_AVAILABLE_IOS(3_0); // 默認是 1.0

4讨越、指定當前縮放因子

[_scrollView setZoomScale:0.8 animated:YES];

- (void)setZoomScale:(CGFloat)scale animated:(BOOL)animated NS_AVAILABLE_IOS(3_0);

//scale

要縮放內(nèi)容到的新值。

animated

若YES永毅,動畫化縮放到時新的縮放大小把跨,NO則立即縮放沼死。

5着逐、設(shè)置縮放顯示到某個區(qū)域耸别,可以帶動畫效果

[_scrollView zoomToRect:newRect animated:YES];

- (void)zoomToRect:(CGRect)rect animated:(BOOL)animated NS_AVAILABLE_IOS(3_0);//給定矩形的大小進行縮放

6、設(shè)置是否允許觸底反彈

scrollView.bouncesZoom=NO;

@property(nonatomic) BOOL bouncesZoom; //若該屬性的值為YES谴麦,在縮放超出最大值或最小值時细移,滾動視圖會臨時播放一個稍超出限制范圍的動畫再返回限制大小搏予。若該屬性為NO,縮放會在達到限制大小時立即停止弧轧,默認為YES雪侥。

? 7、獲取是否正在縮放模式

BOOL zooming= _scrollView.zooming;

@property(nonatomic,readonly,getter=isZooming) BOOL zooming;//用戶發(fā)出了一個縮放手指精绎,該值為YES速缨,否則為NO

8、返回是否正在觸底反彈

?BOOL zoomBouncing= _scrollView.zoomBouncing;

@property(nonatomic,readonly,getter=isZoomBouncing) BOOL zoomBouncing;//滾動視圖縮放超出最大值或最小值時該值為YES代乃;否則值為NO

?9旬牲、設(shè)置是否點擊狀態(tài)欄滾動到scrollView的最上端

?BOOL scrollsToTop= _scrollView.scrollsToTop;

@property(nonatomic) BOOL scrollsToTop __TVOS_PROHIBITED;// 是否允許點擊狀態(tài)欄讓距離狀態(tài)欄最近的scrollView滑動到頂部,默認為YES(注: 在iPhone中如果有多個將該屬性設(shè)置為YES的scrollView,則該方法無效;在iPad中則將距離狀態(tài)欄最近的scrollView滑動到頂部)

8、返回是否正在觸底反彈

BOOL?zoomBouncing= _scrollView.zoomBouncing;

@property(nonatomic,readonly,getter=isZoomBouncing) BOOL zoomBouncing;//滾動視圖縮放超出最大值或最小值時該值為YES搁吓;否則值為NO

五原茅、UIScrollView的手勢屬性

1-->獲取當前用于滑動手勢的手勢識別器(只讀)

? UIPanGestureRecognizer *pan=[_scrollView panGestureRecognizer];

@property(nonatomic, readonly) UIPanGestureRecognizer *panGestureRecognizer NS_AVAILABLE_IOS(5_0);

2-->獲取當前用于擴張/收縮手勢的手勢識別器(只讀)

?UIPinchGestureRecognizer *pin=[_scrollView pinchGestureRecognizer];

@property(nullable, nonatomic, readonly) UIPinchGestureRecognizer *pinchGestureRecognizer NS_AVAILABLE_IOS(5_0);

3、設(shè)置鍵盤消失的模式

typedefNS_ENUM(NSInteger,?UIScrollViewKeyboardDismissMode)?{

????UIScrollViewKeyboardDismissModeNone,//不隱藏鍵盤

????UIScrollViewKeyboardDismissModeOnDrag,??????//手指滑動視圖鍵盤就會消失

????UIScrollViewKeyboardDismissModeInteractive,?//手指滑動視圖后可以與鍵盤交互堕仔,上下滑動鍵盤會跟隨手指上下移動

};

_scrollView.keyboardDismissMode=UIScrollViewKeyboardDismissModeNone;

@property(nonatomic) UIScrollViewKeyboardDismissMode keyboardDismissMode NS_AVAILABLE_IOS(7_0); // 默認是 UIScrollViewKeyboardDismissModeNone

4擂橘、設(shè)置刷新控件

//ios10新特性 自帶刷新控件

self.refresh = [[UIRefreshControl alloc]init];

self.refresh.tintColor = [UIColor blueColor];//控制菊花的顏色

NSAttributedString *string = [[NSAttributedString alloc] initWithString:@"刷刷刷"];

self.refresh.attributedTitle = string;//菊花下面的文字,可利用NSAttributedString設(shè)置各種文字屬性

[self.refresh addTarget:self action:@selector(start1) forControlEvents:(UIControlEventValueChanged)];//刷新方法

ScrollView.refreshControl = self.refresh;

備注:

1.默認的高度和寬度?

2.原來只適用于UITableViewController

3.當拉動刷新時摩骨,UIRefreshControl將在UIControlEventValueChanged事件下被觸發(fā)

@property (nonatomic, strong, nullable) UIRefreshControl *refreshControl NS_AVAILABLE_IOS(10_0) __TVOS_PROHIBITED;

六通贞、UIScrollView的UIScrollViewDelegate屬性

1-->視圖已經(jīng)開始滑動時觸發(fā)的方法

#pragma mark - scrollView delegate-(void)scrollViewDidScroll:(UIScrollView*)scrollView{

if([scrollView isKindOfClass:[UITableViewclass]]) {

// NSLog(@"------是列表---");

}else{

// NSLog(@"------是滾動試圖----");

}

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView;?

2-->視圖已經(jīng)開始縮放時觸發(fā)的方法

-(void)scrollViewDidZoom:(UIScrollView*)scrollView{

CGFloat xcenter = scrollView.center.x, ycenter = scrollView.center.y;

}

- (void)scrollViewDidZoom:(UIScrollView *)scrollView NS_AVAILABLE_IOS(3_2);?

3朗若、視圖開始拖動時觸發(fā)的方法

// 當開始滾動視圖時,執(zhí)行該方法昌罩。一次有效滑動(開始滑動哭懈,滑動一小段距離,只要手指不松開茎用,只算一次滑動)遣总,只執(zhí)行一次。

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{

? ? NSLog(@"scrollViewWillBeginDragging");

}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;//將要開始拖拽時調(diào)用(注: 該方法可能需要先滑動一段時間或距離才會被調(diào)用)

4绘搞、當用戶將要停止拖拽時調(diào)用

// 滑動scrollView,并且手指離開時執(zhí)行傅物。一次有效滑動夯辖,只執(zhí)行一次。

// 當pagingEnabled屬性為YES時董饰,不調(diào)用蒿褂,該方法

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{

? ? NSLog(@"scrollViewWillEndDragging");

}

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0);// 當用戶停止拖拽時調(diào)用(注: 應用程序可以通過修改targetContentOffset參數(shù)的值來調(diào)整內(nèi)容視圖content view停止的位置)

5、視圖拖動結(jié)束時觸發(fā)的方法

// 滑動視圖卒暂,當手指離開屏幕那一霎那啄栓,調(diào)用該方法。一次有效滑動也祠,只執(zhí)行一次昙楚。

// decelerate,指代,當我們手指離開那一瞬后诈嘿,視圖是否還將繼續(xù)向前滾動(一段距離)堪旧,經(jīng)過測試,decelerate=YES

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{

? ? NSLog(@"scrollViewDidEndDragging");

? ? if (decelerate) {

? ? ? ? NSLog(@"decelerate");

? ? }else{

? ? ? ? NSLog(@"no decelerate");

? ? }

? ? CGPoint point=scrollView.contentOffset;

? ? NSLog(@"%f,%f",point.x,point.y);

}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;// 當用戶停止拖拽時調(diào)用(注: 如果內(nèi)容視圖content view在停止拖拽后繼續(xù)移動,則decelerate參數(shù)為YES)

6奖亚、視圖開始減速時觸發(fā)的方法

// 滑動減速時調(diào)用該方法淳梦。

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{

? ? NSLog(@"scrollViewWillBeginDecelerating");

? ? // 該方法在scrollViewDidEndDragging方法之后。

}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;?

?7昔字、視圖減速結(jié)束時觸發(fā)的方法

// 滾動視圖減速完成爆袍,滾動將停止時,調(diào)用該方法作郭。一次有效滑動陨囊,只執(zhí)行一次。

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

? ? NSLog(@"scrollViewDidEndDecelerating");

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

}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;?

8夹攒、視圖動畫結(jié)束時觸發(fā)的方法谆扎,使用set方法設(shè)置偏移量后回觸發(fā)

// 當滾動視圖動畫完成后,調(diào)用該方法芹助,如果沒有動畫堂湖,那么該方法將不被調(diào)用

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{

? ? NSLog(@"scrollViewDidEndScrollingAnimation");

? ? // 有效的動畫方法為:

? ? //? ? - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated 方法

? ? //? ? - (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated 方法

}

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView;?

9闲先、返回進行縮放的視圖

// 返回將要縮放的UIView對象。要執(zhí)行多次

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{

? ? NSLog(@"viewForZoomingInScrollView");

? ? return? self.imgView;

}

- (nullable UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;?

10无蜂、將要開始縮放時調(diào)用

// 當將要開始縮放時伺糠,執(zhí)行該方法。一次有效縮放斥季,就只執(zhí)行一次训桶。

- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view{

? ? NSLog(@"scrollViewWillBeginZooming");

}

- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view NS_AVAILABLE_IOS(3_2);?

11、視圖內(nèi)容結(jié)束縮放時觸發(fā)的方法

// 當縮放結(jié)束后酣倾,并且縮放大小回到minimumZoomScale與maximumZoomScale之間后(我們也許會超出縮放范圍)舵揭,調(diào)用該方法。

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale{

? ? NSLog(@"scrollViewDidEndZooming");

}

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale;?

12躁锡、返回yes午绳,開啟快捷滾動回頂端,將要滾動時調(diào)用

// 指示當用戶點擊狀態(tài)欄后映之,滾動視圖是否能夠滾動到頂部拦焚。需要設(shè)置滾動視圖的屬性:_scrollView.scrollsToTop=YES;

- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView{

? ? return YES;

}

- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView;

13、當scrollView已經(jīng)滑動到頂部時調(diào)用(僅當點擊狀態(tài)欄讓scrollView滑動到頂部才調(diào)用)

// 當滾動視圖滾動到最頂端后杠输,執(zhí)行該方法

- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView{

? ? NSLog(@"scrollViewDidScrollToTop");

}

- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView;?

14赎败、當滾動視圖的inset值發(fā)生變化時調(diào)用

- (void)scrollViewDidChangeAdjustedContentInset:(UIScrollView *)scrollView?{

? ? NSLog(@"scrollViewDidChangeAdjustedContentInset");

}

- (void)scrollViewDidChangeAdjustedContentInset:(UIScrollView *)scrollView API_AVAILABLE(ios(11.0), tvos(11.0));

Tip:判斷uiscrollview是向上滾動還是向下滾動

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

? ? int currentPostion = scrollView.contentOffset.y;?

? ? if (currentPostion - _lastPosition > 25) {?

? ? ? ? _lastPosition = currentPostion;?

? ? ? ? NSLog(@"ScrollUp now");?

? ? }?

? ? else if (_lastPosition - currentPostion > 25)?

? ? {?

? ? ? ? _lastPosition = currentPostion;?

? ? ? ? NSLog(@"ScrollDown now");?

? ? }?

}

參考

iOS開發(fā)UIScrollView使用詳解

iOS控件詳解之UIScrollView

iOS 10 UIScrollView詳解(scrollview自帶刷新UIRefreshControl)

IOS-scrollView詳解

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市蠢甲,隨后出現(xiàn)的幾起案子僵刮,更是在濱河造成了極大的恐慌,老刑警劉巖鹦牛,帶你破解...
    沈念sama閱讀 218,755評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件妓笙,死亡現(xiàn)場離奇詭異,居然都是意外死亡能岩,警方通過查閱死者的電腦和手機寞宫,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,305評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來拉鹃,“玉大人辈赋,你說我怎么就攤上這事「嘌啵” “怎么了钥屈?”我有些...
    開封第一講書人閱讀 165,138評論 0 355
  • 文/不壞的土叔 我叫張陵,是天一觀的道長坝辫。 經(jīng)常有香客問我篷就,道長,這世上最難降的妖魔是什么近忙? 我笑而不...
    開封第一講書人閱讀 58,791評論 1 295
  • 正文 為了忘掉前任竭业,我火速辦了婚禮智润,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘未辆。我一直安慰自己窟绷,他們只是感情好,可當我...
    茶點故事閱讀 67,794評論 6 392
  • 文/花漫 我一把揭開白布咐柜。 她就那樣靜靜地躺著兼蜈,像睡著了一般。 火紅的嫁衣襯著肌膚如雪拙友。 梳的紋絲不亂的頭發(fā)上为狸,一...
    開封第一講書人閱讀 51,631評論 1 305
  • 那天,我揣著相機與錄音遗契,去河邊找鬼辐棒。 笑死,一個胖子當著我的面吹牛姊途,可吹牛的內(nèi)容都是我干的涉瘾。 我是一名探鬼主播知态,決...
    沈念sama閱讀 40,362評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼捷兰,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了负敏?” 一聲冷哼從身側(cè)響起贡茅,我...
    開封第一講書人閱讀 39,264評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎其做,沒想到半個月后顶考,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,724評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡妖泄,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年驹沿,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片蹈胡。...
    茶點故事閱讀 40,040評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡渊季,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出罚渐,到底是詐尸還是另有隱情却汉,我是刑警寧澤掩完,帶...
    沈念sama閱讀 35,742評論 5 346
  • 正文 年R本政府宣布费薄,位于F島的核電站垒迂,受9級特大地震影響锅纺,放射性物質(zhì)發(fā)生泄漏焦匈。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,364評論 3 330
  • 文/蒙蒙 一凡辱、第九天 我趴在偏房一處隱蔽的房頂上張望眉尸。 院中可真熱鬧,春花似錦幻工、人聲如沸励两。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,944評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽当悔。三九已至,卻和暖如春踢代,著一層夾襖步出監(jiān)牢的瞬間盲憎,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,060評論 1 270
  • 我被黑心中介騙來泰國打工胳挎, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留饼疙,地道東北人。 一個月前我還...
    沈念sama閱讀 48,247評論 3 371
  • 正文 我出身青樓慕爬,卻偏偏與公主長得像窑眯,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子医窿,可洞房花燭夜當晚...
    茶點故事閱讀 44,979評論 2 355