ios - UIScrollView:setContentOffset:animated 和 scrollRectToVisible:animated 之间的区别

标签 ios uiscrollview

我已经阅读了 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/

相关文章:

android - Rails protect_from_forgery 与移动应用程序

ios - SpriteKit - 使 Sprite 不受重力影响(像气球一样)

ios - 无法满足 UILabel 对动态 UITableViewCell 的 ContentView 的底部约束

objective-c - 从其他类委托(delegate)返回值

objective-c - 在 UIScrollView 中定位 UIView

php - 无法将图像上传到服务器 ios

ios - 设置 TextField 专注于文本删除

ios - 更改方向时 UIScrollView 的问题,iOS

iphone - 想要缩放图像的位置

ios - UIButton 作为复杂 UIScrollView 上的 subview