Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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
Iphone 如何逐个图像自动滚动图像?_Iphone_Objective C_Uiscrollview - Fatal编程技术网

Iphone 如何逐个图像自动滚动图像?

Iphone 如何逐个图像自动滚动图像?,iphone,objective-c,uiscrollview,Iphone,Objective C,Uiscrollview,我在scrollView上有大约9个图像,我想让它一个图像一个图像地自动滚动(就像第一个图像滚动到第二个,直到最后一个)。我是这样做的: timer = [NSTimer scheduledTimerWithTimeInterval:.0 target:self selector:@selector(scrolling) userInfo:nil repeats:NO]; - (void)scrolling{ CGFloat currentOffset = scrollView.conten

我在scrollView上有大约9个图像,我想让它一个图像一个图像地自动滚动(就像第一个图像滚动到第二个,直到最后一个)。我是这样做的:

timer = [NSTimer scheduledTimerWithTimeInterval:.0 target:self selector:@selector(scrolling) userInfo:nil repeats:NO];

- (void)scrolling{

CGFloat currentOffset = scrollView.contentOffset.x;

if(currentOffset < 2236){

CGFloat newOffset = currentOffset + 172;


[UIScrollView beginAnimations:nil context:NULL];
[UIScrollView setAnimationDuration:2.1];
[scrollView setContentOffset:CGPointMake(newOffset,0.0) animated:YES];
[UIScrollView commitAnimations];

}
timer=[NSTimer scheduledTimerWithTimeInterval:.0目标:自选择器:@selector(滚动)用户信息:无重复:否];
-(无效)滚动{
CGFloat currentOffset=scrollView.contentOffset.x;
如果(电流偏移<2236){
CGFloat newOffset=currentOffset+172;
[UIScrollView beginAnimations:nil上下文:NULL];
[UIScrollView设置动画持续时间:2.1];
[scrollView setContentOffset:CGPointMake(newOffset,0.0)动画:是];
[UIScrollView委员会];
}

但是它只滚动了一次(从第一个图像到第二个图像)。我做错了什么?有什么想法吗?

将“重复”设置为“是”。这是最后一个参数。另外,请确保间隔不是0。(发布的代码显示为0)

timer = [NSTimer scheduledTimerWithTimeInterval:3.0
                                         target:self
                                       selector:@selector(scrolling)
                                       userInfo:nil
                                        repeats:YES];