iPhone开发笔记(14)UIScrollView的边界处理有关问题

iPhone开发笔记(14)UIScrollView的边界处理问题

    在iPhone开发笔记(5)scrollView和pageControl的搭配使用中忽略了UIScrollView的边界处理问题。在UIScrollView中有一个重要的属性bounces,下面是苹果的开发文档中对这个属性的定义。

bounces

A Boolean value that controls whether the scroll view bounces past the edge of content and back again.

@property(nonatomic) BOOL bounces
Discussion

If the value of this property is YES, the scroll view bounces when it encounters a boundary of the content. Bouncing visually indicates that scrolling has reached an edge of the content. If the value is NO, scrolling stops immediately at the content boundary without bouncing. The default value is YES.

Availability
  • Available in iOS 2.0 and later.

(1)当bounces属性设置为YES时,当UIScrollView中图片滑动到边界的时候会出现弹动的效果,就像是Linux中的果冻效果一样。

(2)当bounces属性设置为NO时,当UIScrollView中图片滑动到边界时会直接定在边界就不会有弹动的效果。


    我将bounces属性设置为NO,这样就解决了一个bug。就是在滑动到最左端的图片时,再向左滑动就滑动不了,向右滑动也是一样的道理。这样就解决了数组越界所导致的崩溃问题。