title: animation with infinite scrollView
body: <p>I have 5 pictures inside an infinite scrollView.</p>
  
  <p>So in order to make that <code>scrollView</code> infinite/circular I positioned my images like this:</p>
  
  <p>5 1 2 3 4 5 1
  meaning: last picture first picture second picture.....last picture first picture</p>
  
  <p>And in order for it to become infinite I have the following code:</p>
  
  <pre><code>- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  {
      if(self.scrollView.contentOffset.x == 0){
  
      [self.scrollView scrollRectToVisible:CGRectMake(self.view.frame.size.width*pathImages.count, 0, self.view.frame.size.width, self.view.frame.size.height) animated:NO];  
          }
      else if (self.scrollView.contentOffset.x == self.view.frame.size.width*(pathImages.count+1)) {         
  
      [self.scrollView scrollRectToVisible:CGRectMake(self.view.frame.size.width,0 ,self.view.frame.size.width, self.view.frame.size.height) animated:NO];    
      }
  }
  </code></pre>
  
  <p>which means that when I'm at the last picture the <code>contentOffset</code> of the <code>scrollView</code> is set to go to the first picture-in this way I get an infinite <code>scrollView.</code></p>
  
  <pre><code>  What I wanted next was for my scrollView to slide automatically-for this I set a timer which calls one method-onTimer:
  
  - (void) onTimer{
      NSLog(@"flip pages");
      if(h &lt; pathImages.count*self.view.frame.size.width)
      {
          h+= self.view.frame.size.width;
  
      }
      else
      {
          h=self.view.frame.size.width;
      }
  
      if(self.scrollView.contentOffset.x == 0){
  
          [self.scrollView scrollRectToVisible:CGRectMake(self.view.frame.size.width*pathImages.count, 0, self.view.frame.size.width, self.view.frame.size.height) animated:NO];  
  
      }
  
      if (self.scrollView.contentOffset.x == self.view.frame.size.width*pathImages.count)         
  
      {      
  
          [self.scrollView scrollRectToVisible:CGRectMake(self.view.frame.size.width,0 ,self.view.frame.size.width, self.view.frame.size.height) animated:NO];                         
  
      }
  
      else
  
      [UIView animateWithDuration:1 
                            delay:0 
                          options:UIViewAnimationOptionCurveEaseInOut 
                       animations:^{ self.scrollView.contentOffset = CGPointMake(h, 0); } 
                       completion:NULL];
  }
  </code></pre>
  
  <p>This magic line:   </p>
  
  <pre><code>[UIView animateWithDuration:1 
                                delay:0 
                              options:UIViewAnimationOptionCurveEaseInOut 
                           animations:^{ self.scrollView.contentOffset = CGPointMake(h, 0); } 
                           completion:NULL];
  </code></pre>
  
  <p>does the scoll automatically with animation.</p>
  
  <p>Everything is great except this:</p>
  
  <p>after I view the last picture I should set the offset of scroll view in order to get back to the first picture with animation.</p>
  
  <p>Well if I do that:</p>
  
  <pre><code>if (self.scrollView.contentOffset.x == self.view.frame.size.width*pathImages.count)         
              {      
          [UIView animateWithDuration:1 
                                    delay:0 
                                  options:UIViewAnimationOptionCurveEaseInOut 
                               animations:^{     [self.scrollView scrollRectToVisible:CGRectMake(self.view.frame.size.width,0 ,self.view.frame.size.width, self.view.frame.size.height) animated:NO];  } 
                               completion:NULL];                        
  
          }
  </code></pre>
  
  <p>after the last picture is viewed in order to get to the first picture...it loops through all the other pictures.</p>
  
  <p>What I want is this:after I view the last picture to get me back to the first picture which should be loaded on screen using animation, but without viewing all the other pictures between them.Thanks</p>