Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何以编程方式从头到尾缓慢滚动UIScrollView_Ios_Uiscrollview - Fatal编程技术网

Ios 如何以编程方式从头到尾缓慢滚动UIScrollView

Ios 如何以编程方式从头到尾缓慢滚动UIScrollView,ios,uiscrollview,Ios,Uiscrollview,我有一个水平的UIScroll视图,显示了大约10幅图像。 我知道我们必须使用scrollRectToVisible方法以编程方式移动scrollview。 但我要寻找的是从滚动视图的开始到结束缓慢滚动滚动视图(1秒5个像素) 我看过一些页面,但我不明白如何在代码中集成以下代码: [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDelegate:self]; [UIView setAnimationDuration:(

我有一个水平的UIScroll视图,显示了大约10幅图像。 我知道我们必须使用scrollRectToVisible方法以编程方式移动scrollview。 但我要寻找的是从滚动视图的开始到结束缓慢滚动滚动视图(1秒5个像素)

我看过一些页面,但我不明白如何在代码中集成以下代码:

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

希望它能帮助您……

我个人对此没有任何特殊用途,但我测试了它,它就像一个符咒!嗨,这个代码真的很有效。但是滚动并不平滑。即使将“动画”更改为“是”,滚动也不会平滑。如何实现该功能?滚动取决于间隔时间和Y的增量