ios 基础控件系列之 UIScrollView 初识
来源:互联网 发布:网络错误代码10071 编辑:程序博客网 时间:2024/06/07 16:18
一、UIScrollView 是什么
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 includingUITableView and UITextView.
二、UIScrollView 的使用场景
三、UIScrollView 的基本用法
@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<UIScrollViewDelegate> 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<UIScrollViewDelegate> 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 pagingEnabledscrollview 滚动的翻页效果,效果类似于安卓的viewpager
@property(nonatomic,getter=isScrollEnabled) BOOL scrollEnabledscrollView 是否支持滚动
@property(nonatomic) BOOL showsHorizontalScrollIndicatorscrollview 是否显示水平滚动条
@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就会滚动 自身响应触摸事件
如果为NO,scrollView立马触发- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view方法 ,交给用户自己判断,此方法返回NO,则scrollView 不会将事件传递给view, 返回YES ,表示让view响应这个触摸事件 。注意:默认返回YES
@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刷新控件
- ios 基础控件系列之 UIScrollView 初识
- 【IOS控件详解】之UIScrollView
- ios基本控件之UIScrollView
- iOS控件详解之UIScrollView
- iOS基础开发-UI基础之UIScrollview
- iOS开发UI系列之UIScrollView
- IOS开发(18)之UIScrollView控件
- IOS开发之UIScrollView控件详解
- iOS开发基本控件之UIScrollView
- IOS开发之UIScrollView控件详解
- IOS控件学习之UIScrollView(1)
- IOS控件学习之UIScrollView(2)
- IOS控件学习之UIScrollView(3)
- IOS控件学习之UIScrollView(4)
- IOS控件学习之UIScrollView(5)
- iOS基础控件:UIScrollView 之三大属性 contentOffset 、contentSize 、contentInset 之间的区别
- IOS 基础开发之 UIScrollView的使用
- IOS基础UI之(八)UIScrollView
- 矩阵中的路径—递归
- 如何向一个Fragment传递参数---setArguments方法的介绍
- 网页打开本地应用程序
- Java学习之ArrayList和LinkedList
- cartographer源码分析(21)-sensor-ordered_multi_queue.h
- ios 基础控件系列之 UIScrollView 初识
- xynu第二次比赛
- jsp基础
- CS231n课程笔记翻译9:卷积神经网络笔记
- 牛客三模-大数据方向:选择题和编程题
- 迷雾——dfs
- 齐次含义
- 如何进行反向迭代以及如何实现反向迭代
- jsp语法和jsp三大指令