Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView: difference between setContentOffset:animated and scrollRectToVisible:animated

I have read Apple Scroll View Programming Guide for iOS but still confused about the following part:

Scrolling to a Specific Offset

Scrolling to a specific top-left location (the contentOffset property) can be accomplished in two ways. The setContentOffset:animated: method scrolls the content to the specified content offset. If the animated parameter is YES, the scrolling will animate from the current position to the specified position at a constant rate. If the animated parameter is NO, the scrolling is immediate and no animation takes place. In both cases, the delegate is sent a scrollViewDidScroll: message. If animation is disabled, or if you set the content offset by setting the contentOffset property directly, the delegate receives a single scrollViewDidScroll: message. If animation is enabled, then the delegate receives a series of scrollViewDidScroll: messages as the animation is in progress. When the animation is complete, the delegate receives a scrollViewDidEndScrollingAnimation: message.

Making a rectangle visible

It is also possible to scroll a rectangular area so that it is visible. This is especially useful when an application needs to display a control that is currently outside the visible area into the visible view. The scrollRectToVisible:animated: method scrolls the specified rectangle so that it is just visible inside the scroll view. If the animated parameter is YES, the rectangle is scrolled into view at a constant pace. As with setContentOffset:animated:, if animation is disabled, the delegate is sent a single scrollViewDidScroll: message. If animation is enabled, the delegate is sent a series of scrollViewDidScroll: messages as animation progresses. In the case of scrollRectToVisible:animated: the scroll view’s tracking and dragging properties are also NO.

If animation is enabled for scrollRectToVisible:animated:, the delegate receives a scrollViewDidEndScrollingAnimation: message, providing notification that the scroll view has arrived at the specified location and animation is complete.

I think it is quite similar between setContentOffset:animated and scrollRectToVisible:animated, could someone give some hints about them?

And scrollRectToVisible:animated: is similar to scrollViewDidEndDecelerating:animated: too.

like image 551
ThinkChris Avatar asked Feb 16 '12 00:02

ThinkChris


1 Answers

Short answer:

setContentOffset:animated preserves the zoomscale.

scrollRectToVisible:animated may change it.

like image 166
Peter Sarnowski Avatar answered Sep 28 '22 10:09

Peter Sarnowski