--前言:UIScrollView使用非常广,本文研究UIScrollView各属性和方法,明白它们的意义、作用。在后面的一篇文章有整理UIScrollView一些常见用法以及一些效果的实现思路。

--参考文章:http://www.cocoachina.com/iphonedev/sdk/2010/1224/2503.html  &&  http://zjqzy03080312.blog.163.com/blog/static/18574280720121121105928687  &&  http://blog.csdn.net/wzzvictory/article/details/9264335  
--官方查阅文档  https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIScrollView_Class/Reference/UIScrollView.html

--介绍:UIScrollView用于在一个小范围里显示很大的内容的控件。通过用户平滑、手捏手势,在这个小区域里查看不同内容。是UITableView和UITextView的父类。它是视图,但是比较特殊,可以看成把它看成2层的结构。上面是它的frame层,跟一般试图一样,是它的可见区域,下面层是contentView,可以滑动。

======常用属性======

--CGPoint contentOffSet:contentView的偏移值(正常contentOffSet.x/y值都为正数,但有时(bounces = YES)拽出边界了或者contentInset设置了,还是会出现负数,伴随着contentView滑动,总在改变);

--CGSize contentSize:contentView的大小;

--UIEdgeInsets contentInset:contentView四周的扩展大小,相当改变ContentView的大小,但不是改变contentSize(UIEdgeInsets是个结构体,里面的数值可能是负数,所以扩展的结果可能是contentView被蚕食了一部分。但不管contentView变大了还是变小了,contentOffSet的值还是相比原来大小的偏移);

--id<UIScrollerViewDelegate> delegate:它的代理;

--BOOL directionalLockEnabled:默认是NO,可以在垂直和水平方向同时运动。当值是YES时,假如一开始是垂直或者是水平运动,那么接下来会锁定另外一个方向的滚动。假如一开始是对角方向滚动,则不会禁止某个方向(测试锁定不了,难道是contentsize跟frame高度或宽度一样时用的)

--BOOL bounces:默认是 yes,就是滚动超过边界会反弹有反弹回来的效果。假如是 NO,那么滚动到达边界会立刻停止

--UIScrollViewIndicatorStyle  indicatorStyle:设定滚动条的样式;

--BOOL alwaysBounceVertical:默认no,控制垂直方向遇到边框是否反弹(但bounces为NO时,它为yes,也不反弹。/if YES and bounces is YES, even if content is smaller than bounds, allow drag vertically,测试不好使);

--BOOL alwaysBounceHorizontal:默认no,控制水平方向遇到边框是否反弹(但bounces为NO时,它为yes,也不反弹);

--BOOL pagingEnabled:default NO,contentView是否整页翻动;

--BOOL scrollEnabled:default YES,contentView是否能滚动;

--BOOL showsHorizontalScrollIndicator:default YES,是否显示水平方向的滚动条;

--BOOL showsVerticalScrollIndicator:default YES  是否显示垂直方向的滚动条;

--UIEdgeInsets scrollIndicatorInsets:滚动条在scrollerView中的位置的扩展;

--float  decelerationRate:手指放开后的减速率(测试发现设定这个值没用);

============交互相关============

--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 behavior.  
you can remove the delay in delivery of touchesBegan:withEvent: to subviews by setting delaysContentTouches to NO. 

--UIScrollView的事件响应顺序跟一般的不同,一般的见参考文档, UIScrollView的工作原理,当手指touch的时候,UIScrollView会拦截Event,会等待一段时间,在这段时间内,如果没有手指没有移动,当时间结束时,UIScrollView会发送tracking events到子视图上。在时间结束前,手指发生了移动,那么UIScrollView就会进行移动,从而取笑发送tracking顺序说明: 当手指touch的时候,如果scrollView上面有可交互的视图,track,->或滑动或点击

--BOOL tracking:(readonly)returns YES if user has touched. may not yet have started dragging,即用户按上了,不管滑没滑

--BOOL dragging:(readonly)returns YES if user has started scrolling. this may require some time and or distance to move to initiate dragging,用户在手指在scrolll时,松开了即为no了

--BOOL decelerating:(readonly) returns YES if user isn't dragging (touch up) but scroll view is still moving

 --BOOL delaysContentTouches:就是手指点击到类的时候,如果它为yes,则按之前讲的处理,如果为no,并且点在了“可交互的视图”,立马调用touchesShouldBegin

--BOOL canCancelContentTouches:是if touches have already been delivered to a subview of the scroll view之后发生的事,如果no,即使touch move,也不scroll了,反之如果是yes,tracking后,手指移动,会调用touchesShouldCancelInContentView方法;

--备注:注意顺序,所以当delaysContentTouches为no,canCancelContentTouches为no的时候,touchesShouldBegin方法的返回值不同,滑动在“可交互的视图”的效果也不同,一个滑的动,一个滑不动(注意是touch move了之后的事情)

------------相关方法------------

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

- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view;// default returns YES

--调用地方:方法在UIScrollView的子类中被重写,被调用,

--调用时候:如果delaysContentTouches为yes,则手指点击的时候,会捕获到Event,等待一段时间,在这段时间内,如果没有手指没有移动,并且手指点击在了一个“可交互的视图”则调用touchesShouldBegin,否则类scroll。如果delaysContentTouches为no,只要手指点击了,并且点在一个“可交互的视图”,立刻调用touchesShouldBegin方法。

--备注:当点击子类中的“可交互的视图”上时,如果返回值为no,点击事件不会传递给子视图了。(例如上面加了一个button,如果它返回no,点击button,没有效果)。yes反之;

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

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

--调用时候,上面已讲, --返回值说明:yes,发生滚动,touch不在传递给子视图,no,不滚动,touch传递给子视图

总结: 用户touch--》tracking真--》如果点击一个可交互视图上,发生后面的事,如果没有,一般情况--》

步骤1:根据delaysContentTouches的值,判断什么时候步骤2(立刻还是判断一定条件);

步骤2:调用touchesShouldBegin方法,如果返回值为yes,touch事件传给子视图;如果为no,touch事件不传给子视图,进入状态n。(跳转)

步骤3:touch move的,如果canCancelContentTouches为no,不调用touchesShouldCancelInContentView方法,类也不scroll,进入状态m,如果canCancelContentTouches为yes,调用touchesShouldCancelInContentView,根据touchesShouldCancelInContentView方法的返回值,如果是yes,进入状态m。如果是no,进入状态s。

状态n:tracking为真,如果touch move的就scroll,touch松开,进入状态e

状态s:touch move中,类scroll,如果touch 松开,进入状态e

状态m:touch move中,类不scroll,如果touch 松开,进入状态e

状态e:结束

============缩放相关============

--float minimumZoomScale缩放的最小比例;

--float maximumZoomScale:缩放的最大比例;

--float zoomScale缩放的比例(在minimumZoomScale和maximumZoomScale之间变化);如果设置的话,写在 [self.view addSubview:_scrollView];之后才能好使

 --BOOL bouncesZoom :控制缩放到边界的时是否会反弹;

--BOOL zooming(readonly):判断控件的大小是否正在缩放;

--BOOL zoomBouncing(readonly):判断控件是否缩放到了最大/最小;

--备注:如果scollView设置了缩放,但又设置contentszie等,刚开始没缩放的时候能scroll,但一但缩放过,就只能缩放,不能scroll了

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

设置单击状态栏控件是否滚动到顶部

--BOOL scrollsToTop

UIScrollView方法 属性详解的更多相关文章

  1. asp.net中C#对象与方法 属性详解

    C#对象与方法 一.相关概念: 1.对象:现实世界中的实体 2. 类:具有相似属性和方法的对象的集合 3.面向对象程序设计的特点:封装  继承 多态 二.类的定义与语法 1.定义类: 修饰符 类名称 ...

  2. window.location的方法属性详解

    示例URL:http://b.a.com:88/index.php?name=kang&when=2011#first 属性 含义 值 protocol: 协议 "http:&quo ...

  3. python开发笔记-ndarray方法属性详解

    Python中的数组ndarray是什么? 1.NumPy中基本的数据结构 2.所有元素是同一种类型 3.别名是array 4.利于节省内存和提高CPU计算时间 5.有丰富的函数 ndarray的创建 ...

  4. jQuery操纵DOM元素属性 attr()和removeAtrr()方法使用详解

    jQuery操纵DOM元素属性 attr()和removeAtrr()方法使用详解 jQuery中操纵元素属性的方法: attr(): 读或者写匹配元素的属性值. removeAttr(): 从匹配的 ...

  5. C#类、对象、方法和属性详解

    C#类.对象.方法和属性详解 一.相关概念: 1.对象:现实世界中的实体(世间万物皆对象) 2.类:具有相似属性和方法的对象的集合 3.面向对象程序设计的特点:封装 继承 多态 4.对象的三要素:属性 ...

  6. CentOS 6.3下Samba服务器的安装与配置方法(图文详解)

    这篇文章主要介绍了CentOS 6.3下Samba服务器的安装与配置方法(图文详解),需要的朋友可以参考下   一.简介  Samba是一个能让Linux系统应用Microsoft网络通讯协议的软件, ...

  7. OutputCache属性详解(一)一Duration、VaryByParam

    目录 OutputCache概念学习 OutputCache属性详解(一) OutputCache属性详解(二) OutputCache属性详解(三) OutputCache属性详解(四)— SqlD ...

  8. OutputCache属性详解(三)— VaryByHeader,VaryByCustom

    目录 OutputCache概念学习 OutputCache属性详解(一) OutputCache属性详解(二) OutputCache属性详解(三) OutputCache属性详解(四)— SqlD ...

  9. HTML video 视频标签全属性详解

    HTML 5 video 视频标签全属性详解   现在如果要在页面中使用video标签,需要考虑三种情况,支持Ogg Theora或者VP8(如果这玩意儿没出事的话)的(Opera.Mozilla.C ...

随机推荐

  1. Core 发布至Linux

    ASP.NET Core 发布至Linux生产环境 Ubuntu 系统 ASP.NET Core 发布至Linux生产环境 Ubuntu 系统,之前跟大家讲解了 dotnet publish 发布,而 ...

  2. HDU 1240 Asteroids!

    三维广搜 #include <cstdio> #include <iostream> #include <cstring> #include <queue&g ...

  3. java 面试 复习 II

    1  break  多重 循环跳出当前循环到上层循环再执行. 如若想跳出多重循环可以使用标号 2  byte,short,char都可以隐含转换为int.可以用在switch 表达式.long和str ...

  4. 【opengl】OpenGL中三维物体显示在二维屏幕上显示的变换过程

    转自:http://blog.sina.com.cn/s/blog_957b9fdb0100zesv.html 为了说明在三维物体到二维图象之间,需要经过什么样的变换,我们引入了相机(Camera)模 ...

  5. $.getJSON(url,function success(){})回调函数不起作用

    有个问题好久没有解决,就是: $.getJSON(url,function success(){}) 其中的回调函数,总也不执行. 以前也做过,但那都是CTRL+C,CTRL+V,也没有细想. 目标就 ...

  6. poj 1050 To the Max(线性dp)

    题目链接:http://poj.org/problem?id=1050 思路分析: 该题目为经典的最大子矩阵和问题,属于线性dp问题:最大子矩阵为最大连续子段和的推广情况,最大连续子段和为一维问题,而 ...

  7. float存储方式编程验证

    取出float在内存中的编码: void printFloatAsBinary(float f){ // 二进制的位数 const int bits = sizeof(f) * 8; // 将floa ...

  8. find the most comfortable road(并差集,找差值最小的权值)

    find the most comfortable road Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  9. Cloud Foundry warden container 安全性探讨

    本文将从Cloud Foundry中warden container的几个方面探讨warden container的安全性. 1. warden container互訪 1.1.  互訪原理· 在Cl ...

  10. C-C Radar Installation 解题报告

    C-C    Radar Installation   解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#pr ...