如何以编程方式从头到尾缓慢滚动 UIScrollView [英] How can I programmatically scroll UIScrollView from start to end slowly
本文介绍了如何以编程方式从头到尾缓慢滚动 UIScrollView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个显示大约 10 张图像的水平 UIScrollview.我知道我们必须使用 scrollRectToVisible 方法以编程方式移动滚动视图.但我正在寻找的是从滚动视图的开始到结束缓慢滚动滚动视图(1 秒内 5 个像素).
I've a horizontal UIScrollview that shows around 10 images. I know that we've to use scrollRectToVisible method to move the scrollview programmatically. But what I am looking for is to scroll the scroll view slowly (5 pixels in 1 second) from start to end of the scroll view.
我看过一些页面,但我不明白如何在我的代码中集成以下代码:
I have seen some pages, but I didn't understand how to integrate following code in my code:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:(abs(rMid-pMid)*0.3)];
scrollMid.contentOffset = CGPointMake(rMid*320, 0);
[UIView commitAnimations];
推荐答案
你可以像
- (void) viewDidLoad
{
if (scrollingTimer == nil)
{
scrollingTimer = [NSTimer scheduledTimerWithTimeInterval:(0.06)
target:self selector:@selector(autoscrollTimerFired) userInfo:nil repeats:YES];
}
}
- (void) autoscrollTimerFired
{
if (scrollPoint.y == 583) // at where you want to stop scroll
{
[scrollingTimer invalidate];
scrollingTimer = nil;
}
scrollPoint = CGPointMake(scrollPoint.x, scrollPoint.y + 1);
[self.scrollView setContentOffset:scrollPoint animated:NO];
}
希望对你有帮助...
这篇关于如何以编程方式从头到尾缓慢滚动 UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文