如何使动画的UIScrollView期间发送scrollViewDidScroll消息 [英] How to make UIScrollView send scrollViewDidScroll messages during animations

查看:126
本文介绍了如何使动画的UIScrollView期间发送scrollViewDidScroll消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户手动滚动通过我的UIScrollView,我委托的scrollViewDidScroll方法被反复动画过程中调用,与contentOffset新近更新的值。
当我打电话[滚动视图setContentOffset:320动画片:YES,然后委托方法被调用以同样的方式。
我决定,正常的滚动速度是用户体验的太快,所以封闭了[滚动视图setContentOffset:320]在animatedWithDuration:块,如苹果建议UIView类参考

When the user manually scrolls through my UIScrollView, the scrollViewDidScroll method of my delegate gets called repeatedly during the animation, with newly updated values of the contentOffset. When I call "[scrollView setContentOffset:320 animated:YES", then the delegate method gets called in the same way. I decided that the normal scroll speed is too fast for the user experience, so enclosed a "[scrollView setContentOffset:320]" in an "animatedWithDuration:" block, as Apple recommends in the UIView class reference.

但是......现在我的scrollViewDidScroll方法被用在最终值的开头动画调用一次,而不是动画过程中了。我得到同样的效果时,我用的是旧的beginAnimations:方法来代替。

But... now my scrollViewDidScroll method gets called only once at the beginning of the animation with the final value, and not during the animation anymore. I get the same effect when I use the old "beginAnimations:" methods instead.

所以...任何人知道如何解决此问题?

So... anybody knows how to solve this?

顺便说一下,所述的UIScrollView的setContentOffset方法示出相同的行为。它使用了动画过程中被调用,而现在只调用一次。

By the way, the "setContentOffset" method of the UIScrollView shows the same behaviour. It used to be called during the animations, and now is called only once.

推荐答案

由于Fichek的提示,我得到这个工作。像Fichek说,你不要动画过程中得到改变性质的任何通知。因此,关键是要确保任何依赖于更改的属性也动画在同一时间。你需要设置自己的动画在同一区块的原始属性。
如果然后设置UIViewAnimationOptionAllowUserInteraction的动画,那么相同的属性仍然可以工作的正在进行的任何用户互动 - 而出奇地好,我不得不说。

Thanks to Fichek's hint, I have gotten this to work. Like Fichek said, you don't get any notifications of changed properties during animation. So the trick is, to make sure that anything that depends on the changed property is also animated at the same time. You need to setup their animations in the same block as the original property. If you then set the "UIViewAnimationOptionAllowUserInteraction" on the animation, then any ongoing user interaction of the same properties will still work - and surprisingly well, I have to say.

有关我的具体案例 - 保持拖视图固定的,而滚动的UIScrollView下面 - 这里是如何设置我的动画:

For my concrete case - to keep a dragged view stationary, while the UIScrollView scrolls underneath - here is how I setup my animation:

[UIView animateWithDuration:0.5 delay:0
                    options:UIViewAnimationOptionAllowUserInteraction
                 animations:^{
    [theScrollView setContentOffset:offset];
    // compute newCenter from the new offset
    theDraggedView.center = newCenter;
} completion:^(BOOL finished) {}];

这篇关于如何使动画的UIScrollView期间发送scrollViewDidScroll消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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