如何计算运动中的UIScrollView的目标contentOffset [英] How to calculate the destination contentOffset of a UIScrollView in motion

查看:98
本文介绍了如何计算运动中的UIScrollView的目标contentOffset的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UIScrollView作为使用核心动画的组件的基础。当用户滑动视图时,我想根据滚动视图的目标(静止)位置定位元素。为此,我需要在scrollViewWillBeginDecelerating:方法或类似方法中计算UIScrollView的目标contentOffset。

I'm using a UIScrollView as the basis of a component that makes use of core animation. When the user swipes the view I would like to position elements according to the destination (resting) position of the scroll view. For this, I need to calculate the destination contentOffset of the UIScrollView in the scrollViewWillBeginDecelerating: method or similar.

我需要这样做的原因是我将使用目标contentOffset用于将嵌套在scrollview的contentView中的视图动画化为最终位置。我当然可以在contentOffset或类似位置上设置观察者,但这会导致动画混乱,因为嵌套视图随后将在减速期间多次更新其位置。我希望这种情况只发生一次。

The reason I need this is that I'll be using the destination contentOffset to animate views nested within the scrollview's contentView to their final position. I could of course set up an observer on the contentOffset or similar, but this would result in chaotic animation as the nested views would then update their positions multiple times during deceleration. I'd like this to happen just the once.

有没有简单的方法可以做到这一点?

Is there a simple way to do this?

推荐答案

为此有一个委托方法:

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS5(5_0);

根据文档:

称为如果用户拖动,手指向上。速度以点/秒为单位。可以更改targetContentOffset来调整滚动视图的停止位置。当pagingEnabled为YES时不调用

Called on finger up if the user dragged. velocity is in points/second. targetContentOffset may be changed to adjust where the scroll view comes to rest. not called when pagingEnabled is YES

这篇关于如何计算运动中的UIScrollView的目标contentOffset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆