在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];
}
代碼運行之後,只有第一張圖片滾動了。哪出錯了?
設置repeat為YES,這是最後一個參數。並保證間隔不為0,看代碼裡是0。
timer = [NSTimer scheduledTimerWithTimeInterval:3.0
target:self
selector:@selector(scrolling)
userInfo:nil
repeats:YES];