UIScrollView 和 setContentOffset

发布于 2024-11-06 22:36:41 字数 149 浏览 0 评论 0原文

我的问题是关于这个方法:
(void)setContentOffset:(CGPoint)contentOffsetanimated:(BOOL)animated

我已阅读文档,但我不明白此方法的用途。

感谢您的回答。

My question is about this method:
(void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated

I have read the documentation, but i don't understand what this method is for.

thanks for your answers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尹雨沫 2024-11-13 22:36:41

UIScrollView 允许您拥有比屏幕上可以查看的内容更大的内容。
在下图中,您可以看到一个大的红色矩形,里面有一个绿色矩形。

UIScrollView 的 contentArea 属性定义视图的逻辑大小(红色矩形)。
滚动视图的可见区域由绿色矩形表示。 contentOffset 是可见区域的左上角。改变contentOffset,可见区域将会移动。

(void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated

上面的方法会将 contentOffset(绿色矩形的左上角)移动到指定位置,从而移动可见区域(绿色矩形)。

希望这有帮助。

在此处输入图像描述

UIScrollView lets you have content that is larger than what you can view on the screen.
In the image below you can see a large red rectangle with a green rectangle inside.

The contentArea property of the UIScrollView defines the logical size of your view (the red rectangle).
The visible area of the scroll view is represented by the green rectangle. The contentOffset is the upper left corner of the visible area. Changing contentOffset, the visible area will move around.

(void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated

The method above will move the contentOffset (the upper left corner of the green rectangle) to a specified location, thus moving the visible area (the green rectangle).

Hope this helps.

enter image description here

眼波传意 2024-11-13 22:36:41

文档中所述。

滚动到特定偏移量

滚动到特定左上角位置(contentOffset 属性)可以通过两种方式完成。 setContentOffset:animated: 方法将内容滚动到指定的内容偏移量。如果动画参数为YES,则滚动将以恒定速率从当前位置动画到指定位置。如果动画参数为NO,则立即滚动并且不发生动画。在这两种情况下,委托 scrollViewDidScroll: 消息。如果禁用动画,或者通过直接设置 contentOffset 属性来设置内容偏移量,则委托会收到一条 scrollViewDidScroll: 消息。如果启用了动画,则当动画正在进行时,委托会收到一系列 scrollViewDidScroll: 消息。动画完成后,委托会收到 scrollViewDidEndScrollingAnimation: 消息。

即简单来说,如果您想通过传递滚动位置值(即滚动量)以编程方式滚动 UIScrollView,您可以使用此方法。

该方法还调用委托scrollViewDidScroll:,即UIScrollView类的委托方法,通过该方法可以维护UIScrollView的滚动量。

As mentioned in documentation.

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 delegates scrollViewDidScroll: messages. 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.

i.e. In simple words if you want to scroll UIScrollView programatically by passing scrolling position values i.e. how much amount to scroll, you can use this method.

This method also calls delegate scrollViewDidScroll: i.e. delegate method of UIScrollView class through which you can maintain the amount of scrolling of UIScrollView.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文