我已经阅读了 Apple Scroll View Programming Guide for iOS 但仍然对以下部分感到困惑:
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.
我认为 setContentOffset:animated 和 scrollRectToVisible:animated 之间非常相似,有人可以给出一些关于它们的提示吗?
而 scrollRectToVisible:animated: 也类似于 scrollViewDidEndDecelerating:animated:。
最佳答案
简答:
setContentOffset:animated 保留缩放比例。
scrollRectToVisible:animated 可能会改变它。
关于ios - UIScrollView:setContentOffset:animated 和 scrollRectToVisible:animated 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9303983/