Iphone 如何逐个图像自动滚动图像?
我在scrollView上有大约9个图像,我想让它一个图像一个图像地自动滚动(就像第一个图像滚动到第二个,直到最后一个)。我是这样做的: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
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];