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