iOS UIScrollView常用属性、回调方法


//1、常用属性

(1)常用属性:

1)@property(nonatomic)CGPointcontentOffset; 这个属性⽤用来表⽰示UIScrollView滚动的位置

2)@property(nonatomic)CGSizecontentSize;这个属性⽤用来表⽰示UIScrollView内容的尺⼨寸,滚动范围(能滚多远)

3)@property(nonatomic)UIEdgeInsetscontentInset; 这个属性能够在UIScrollView的4周增加额外的滚动区域 

(2)其他属性:

1)@property(nonatomic) BOOL bounces;  设置UIScrollView是否需要弹簧效果 

2)@property(nonatomic,getter=isScrollEnabled)BOOLscrollEnabled; 设置UIScrollView是否能滚动 

3)@property(nonatomic) BOOL showsHorizontalScrollIndicator; 是否显⽰示⽔水平滚动条 

4)@property(nonatomic) BOOL showsVerticalScrollIndicator; 是否显⽰示垂直滚动条 

4.注意点

• 如果UIScrollView⽆无法滚动,可能是以下原因: 

(1)没有设置contentSize

(2) scrollEnabled = NO

(3) 没有接收到触摸事件:userInteractionEnabled = NO

(4)没有取消autolayout功能(要想scrollView滚动,必须取消autolayout) 


 //2、回调方法


- (void)scrollViewDidScroll:(UIScrollView *)scrollView;  // 只要view有滚动(不管是拖、拉、放大、缩小  等导致) 都会执行此函数---any offset changes


- (void)scrollViewDidZoom:(UIScrollView *)scrollView __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2); // view的缩放,参考另一篇博文---any zoom scale changes


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

// 将要开始拖拽,手指已经放在view上并准备拖动的那一刻

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


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

// 将要结束拖拽,手指已拖动过view并准备离开手指的那一刻  注意:当属性pagingEnabledYES时此函数不被调用

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);


// called on finger up if the user dragged. decelerate is true if it will continue moving afterwards

// 已经结束拖拽,手指刚离开view的那一刻

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


// called on finger up as we are moving

//  view将要开始减速 view滑动之后有惯性

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


// called when scroll view grinds to a halt

// view已经停止滚动

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


// called when setContentOffset/scrollRectVisible:animated: finishes. not called if not animating

// 有动画时调用

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


// return a view that will be scaled. if delegate returns nil, nothing happens

// 直接看英文吧

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


// called before the scroll view begins zooming its content

- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2);


// scale between minimum and maximum. called after any 'bounce' animations

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


// return a yes if you want to scroll to the top. if not defined, assumes YES

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


// called when scrolling animation finished. may be called immediately if already at top

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


@end


执行顺序:

willBeginDragging

DidScroll

willEndDragging

DidEndDragging

DidScroll

willBeginDecelerating

DidScroll

DidEndDecelerating


#define DELEGATE_CALLBACK(DELEGATE, SEL) if (DELEGATE && [DELEGATE respondsToSelector:@selector(SEL)]) [DELEGATE performSelector:@selector(SEL)]

#define DELEGATE_CALLBACK_ONE_PARAMETER(DELEGATE, SEL, X) if (DELEGATE && [DELEGATE respondsToSelector:@selector(SEL)]) [DELEGATE performSelector:@selector(SEL) withObject:X]

#define DELEGATE_CALLBACK_TWO_PARAMETER(DELEGATE, SEL, X, Y) if (DELEGATE && [DELEGATE respondsToSelector:@selector(SEL)]) [DELEGATE performSelect



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值