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。就是在滑動到最左端的圖片時,再向左滑動就滑動不了,向右滑動也是一樣的道理。這樣就解決了數組越界所導致的崩潰問題。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章