iPhone - 我怎么能以编程方式慢慢地从头到尾滚动UIScrollView [英] iPhone - how can I programatically scroll UIScrollView from start to end slowly

查看:93
本文介绍了iPhone - 我怎么能以编程方式慢慢地从头到尾滚动UIScrollView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个水平的UIScrollview,显示大约10张图片。
我知道我们要使用scrollRectToVisible方法以编程方式移动scrollview。
但我想要的是从滚动视图的开始到结束慢慢滚动滚动视图(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 programatically. 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];

有人可以帮助我吗?

推荐答案

你可以使用 NSTimer 喜欢

- (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];
}

希望能帮助你...

这篇关于iPhone - 我怎么能以编程方式慢慢地从头到尾滚动UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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