以编程方式滑动 UIScrollView
Flick a UIScrollView programmatically
当用户在 UIScrollView 上做出轻弹手势时,UIScrollView 获得动力并开始移动,然后减速并最终停止。
但是我怎样才能以编程方式实现这一点呢?我的意思是不用手指轻弹,UIScrollView 就开始自动移动,然后减慢到 0 的速度。
在我的应用程序中,我使我的 UIScrollView 不同于普通的 UIScrollView(假设它看起来像一个滚轮),所以我想提示用户他可以滚动它(然后一切开始!)
我用谷歌搜索了很多,但似乎没有办法解决我的问题。 setContentOffset 无法产生自然的 "slow down and stop at somewhere ahead" 效果。
如有任何想法,我们将不胜感激。
提前致谢。
试试,像这样>
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDelay:.8];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:(abs(1-3)*0.3)];
self.myScroll.contentOffset = CGPointMake(0, 500);
[UIView commitAnimations];
目前不是你所需要的,但你可以自定义这段代码,可能一切正常)
或使用此代码>
[UIView animateWithDuration:2.
delay:0.3
usingSpringWithDamping:1.
initialSpringVelocity:7.
options:UIViewAnimationOptionCurveEaseInOut animations:^{
//Animations
self.myScroll.contentOffset = CGPointMake(0, 500);
}
completion:^(BOOL finished) {
//Completion Block
}];
我觉得很像你想要的(动画效果像滑动效果)
当用户在 UIScrollView 上做出轻弹手势时,UIScrollView 获得动力并开始移动,然后减速并最终停止。 但是我怎样才能以编程方式实现这一点呢?我的意思是不用手指轻弹,UIScrollView 就开始自动移动,然后减慢到 0 的速度。
在我的应用程序中,我使我的 UIScrollView 不同于普通的 UIScrollView(假设它看起来像一个滚轮),所以我想提示用户他可以滚动它(然后一切开始!)
我用谷歌搜索了很多,但似乎没有办法解决我的问题。 setContentOffset 无法产生自然的 "slow down and stop at somewhere ahead" 效果。
如有任何想法,我们将不胜感激。
提前致谢。
试试,像这样>
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDelay:.8];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:(abs(1-3)*0.3)];
self.myScroll.contentOffset = CGPointMake(0, 500);
[UIView commitAnimations];
目前不是你所需要的,但你可以自定义这段代码,可能一切正常)
或使用此代码>
[UIView animateWithDuration:2.
delay:0.3
usingSpringWithDamping:1.
initialSpringVelocity:7.
options:UIViewAnimationOptionCurveEaseInOut animations:^{
//Animations
self.myScroll.contentOffset = CGPointMake(0, 500);
}
completion:^(BOOL finished) {
//Completion Block
}];
我觉得很像你想要的(动画效果像滑动效果)