The UIScrollView class provides support for displaying content that is larger than the size of the application’s window. It enables users to scroll within that content by making swiping gestures, and to zoom in and back from portions of the content by making pinching gestures.
UIScrollView is the superclass of several UIKit classes including UITableView and UITextView.
@property(nonatomic) CGPoint contentOffset; // default CGPointZero
@property(nonatomic) CGSize contentSize; // default CGSizeZero
@property(nonatomic) UIEdgeInsets contentInset; // default UIEdgeInsetsZero. add additional scroll area around content
@property(nullable,nonatomic,weak) id delegate; // default nil. weak reference
@property(nonatomic,getter=isDirectionalLockEnabled) BOOL directionalLockEnabled; // default NO. if YES, try to lock vertical or horizontal scrolling while dragging
@property(nonatomic) BOOL bounces; // default YES. if YES, bounces past edge of content and back again
@property(nonatomic) BOOL alwaysBounceVertical; // default NO. if YES and bounces is YES, even if content is smaller than bounds, allow drag vertically
@property(nonatomic) BOOL alwaysBounceHorizontal; // default NO. if YES and bounces is YES, even if content is smaller than bounds, allow drag horizontally
@property(nonatomic,getter=isPagingEnabled) BOOL pagingEnabled __TVOS_PROHIBITED;// default NO. if YES, stop on multiples of view bounds
@property(nonatomic,getter=isScrollEnabled) BOOL scrollEnabled; // default YES. turn off any dragging temporarily
@property(nonatomic) BOOL showsHorizontalScrollIndicator; // default YES. show indicator while we are tracking. fades out after tracking
@property(nonatomic) BOOL showsVerticalScrollIndicator; // default YES. show indicator while we are tracking. fades out after tracking
@property(nonatomic) UIEdgeInsets scrollIndicatorInsets; // default is UIEdgeInsetsZero. adjust indicators inside of insets
@property(nonatomic) UIScrollViewIndicatorStyle indicatorStyle; // default is UIScrollViewIndicatorStyleDefault
@property(nonatomic) CGFloat decelerationRate NS_AVAILABLE_IOS(3_0);
@property(nonatomic,readonly,getter=isTracking) BOOL tracking; // returns YES if user has touched. may not yet have started dragging
@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
@property(nonatomic,readonly,getter=isDecelerating) BOOL decelerating; // returns YES if user isn't dragging (touch up) but scroll view is still moving
@property(nonatomic) BOOL delaysContentTouches; // default is YES. if NO, we immediately call -touchesShouldBegin:withEvent:inContentView:. this has no effect on presses
@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
@property(nonatomic) CGSize contentSize;
官方文档给了一句话解释 The size of the content view
contentview 的尺寸,是指scrollview 可以滚动的范围,例如 scrollview 的frame 是(0,0,320,640),contentSize 是(640,1280) 则代表 scrollview 可以左右滚动一屏幕,上下滚动一屏幕。
@property(nonatomic) CGPoint contentOffset;
The point at which the origin of the content view is offset from the origin of the scroll view.
是scrollview当前显示区域顶点相对于frame顶点的偏移量,在上个例子中,如果当前 scrollview 向下滚动了一屏,则当前的 contentOffset 是(0,640)
@property(nonatomic) UIEdgeInsets contentInset;
是 scrollview 的内边距
@property(nullable,nonatomic,weak) id delegate;
scrollview 的代理(协议),类似于 java 中的接口(interface),有java 基础的很好理解,这里理解为回调就可以了。
@property(nonatomic,getter=isDirectionalLockEnabled) BOOL directionalLockEnabled;
scrollview 的滚动方向控制,如果设置为true,则当用户垂直或者水平滚动的时候,另一个方向会被锁定,如果用户滚动的放心是斜着的,则这个属性失效
@property(nonatomic) BOOL bounces;
scrollview 滑动到边界的时候,是否有 回弹效果
@property(nonatomic) BOOL alwaysBounceVertical;
scrollview 的垂直滚动,当 bounces 属性设置为true,且alwaysBounceVertical 设置为true,则即使内容 比边界小,依然可以垂直滚动
@property(nonatomic) BOOL alwaysBounceHorizontal;
同上
@property(nonatomic,getter=isPagingEnabled) BOOL pagingEnabled
scrollview 滚动的翻页效果,效果类似于安卓的viewpager
@property(nonatomic,getter=isScrollEnabled) BOOL scrollEnabled
scrollView 是否支持滚动
@property(nonatomic) BOOL showsHorizontalScrollIndicator
scrollview 是否显示水平滚动条
@property(nonatomic) BOOL showsVerticalScrollIndicator
是否显示垂直滚动条
@property(nonatomic) UIEdgeInsets scrollIndicatorInsets
滚动条到边界的距离
@property(nonatomic) UIScrollViewIndicatorStyle indicatorStyle
滚动条的风格
@property(nonatomic) CGFloat decelerationRate
减速率,值用户滑动后,scrollview滚动的减速度,有两个常量可以用
UIScrollViewDecelerationRateNormal
UIScrollViewDecelerationRateFast
@property(nonatomic,readonly,getter=isTracking) BOOL tracking
返回true 代表用户已经触碰了scrollview,即使没有滑动
@property(nonatomic,readonly,getter=isDragging) BOOL dragging
用户是否已经在滚动 scrollview
@property(nonatomic,readonly,getter=isDecelerating) BOOL decelerating
是否是 用户滑动后,scrollview 的减速状态
@property(nonatomic) BOOL delaysContentTouches
如果为YES,就会延迟处理这个触摸手势的意图,直到确定了在极短时间内是否发生了滚动,如果没有滚动 ,就把触摸事件传递给触摸的subview处理 (可以响应事件的控件) ,如果滚动了,则scrollView就会滚动 自身响应触摸事件
@property(nonatomic) BOOL canCancelContentTouches
@property(nonatomic) CGFloat minimumZoomScale
最小缩放因子
@property(nonatomic) CGFloat zoomScale
缩放比例
@property(nonatomic) BOOL bouncesZoom
控制缩放的时候是否会反弹
@property(nonatomic,readonly,getter=isZooming) BOOL zooming
当前是否处于缩放状态
@property(nonatomic,readonly,getter=isZoomBouncing) BOOL zoomBouncing
当前是否处于缩放反弹状态
@property(nonatomic) BOOL scrollsToTop
触摸状态栏是否返回顶部
@property(nonatomic, readonly) UIPanGestureRecognizer *panGestureRecognizer
拖动手势
@property(nullable, nonatomic, readonly) UIPinchGestureRecognizer *pinchGestureRecognizer
向里或向外捏的手势
@property(nonatomic, readonly) UIGestureRecognizer *directionalPressGestureRecognizer
@property(nonatomic) UIScrollViewKeyboardDismissMode keyboardDismissMode
键盘消失模式
UIScrollViewKeyboardDismissModeOnDrag
ScrollView拖动的时候消失
UIScrollViewKeyboardDismissModeInteractive
交互式效果,拖动ScrollView可以使键盘移出屏幕范围,可取消
@property (nonatomic, strong, nullable) UIRefreshControl *refreshControl
刷新控件