UIScrollView scrollRectToVisible 以自定义速度

时间:2023-02-15
本文介绍了UIScrollView scrollRectToVisible 以自定义速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UIScrollView,我在上面调用 scrollRectToVisible:animated:YES.我想设置动画的速度.可以吗?

I have a UIScrollView and I'm calling scrollRectToVisible:animated:YES on it. I would like to set the speed at which it is animated. Can that be done?

推荐答案

我最终找到了解决方案.就我而言,滚动在启动后以编程方式进行动画处理,以模仿老虎机(带有 3 个水平 UIScrollView).正在使用 scrollRectToVisible:animated: 方法执行此操作.

I ended up finding a solution. In my case, the scrolling was animated programmatically after launch, to mimic a slot machine (with 3 horizontal UIScrollViews). Was doing this with the scrollRectToVisible:animated: method.

我必须使用 UIView 的 beginAnimation 设置自定义速度:

I got to set a custom speed using UIView's beginAnimation:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:(abs(rMid-pMid)*0.3)];
scrollMid.contentOffset = CGPointMake(rMid*320, 0);
[UIView commitAnimations];

AnimationDuration 取决于滚动条在每个绘图"之间移动的距离.

AnimationDuration depends on the distance the scroller has to move between each "drawing".

这篇关于UIScrollView scrollRectToVisible 以自定义速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:为什么添加对象后 UIScrollView 不会完全滚动?使用 下一篇:如何在单击 UIPageControl 的点时更改页面

相关文章

最新文章