iOS 设置 setContentOffset 时序

本文介绍了UIScrollView中通过 setContentOffset:animated: 方法实现的滚动控制。详细解释了如何通过此方法设置UIScrollView的具体滚动位置,以及动画效果的开启与关闭对于scrollViewDidScroll:消息的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转自stackoffoverflow: 


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 UIScrollViewclass through which you can maintain the amount of scrolling of UIScrollView.

总结起来,如果直接调用 setContentOffset:方法,或者setContentOffset: animated: 为NO,  在方法结束就可以立刻改变contentoffset值;如果设为YES,只能在调用这个方法的函数执行结束后才能得到新的contentoffset值。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值