Scrolling animation – UIScrollView

So I wanted an animated UIScrollView which iterated around a collection of UIViews that had been programmatically added to my UIScrollView.

Problem I ran into was starting the animation over after the final view had been displayed.

After initially ignoring the completion:^ option, I found a neat little way to recall the function for each view and then revert when the first view once a counter position had been reached.

- (void)scrollFeaturedView:(int)counter{
CGRect frame;
frame.origin.x = self.FeaturedView.frame.size.width * counter;
frame.origin.y = 0;
frame.size = self.FeaturedView.frame.size;

[UIView animateWithDuration:1
delay:3
options: UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction
animations:^{ [self.FeaturedView scrollRectToVisible:frame animated:NO]; }
completion:^ (BOOL finished)
{
if (finished) {
if (counter != [articleLists count])
{
[self scrollFeaturedView:counter + 1];
}
else
{
[self scrollFeaturedView:0];
}
}
}];
} As you can see the counter position is based on a count of an list I have (which in turn is the data I used to add the UIViews programmatically).

Hope you enjoy and comments always welcome.

C.