Show Menu

Do you have a job opening?

Submit your 30 day Job Listing for FREE

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
	options: UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction
	animations:^{ [self.FeaturedView scrollRectToVisible:frame animated:NO]; }
	completion:^ (BOOL finished)
			if (finished) {
				if (counter != [articleLists count])
						[self scrollFeaturedView:counter + 1];
						[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 comment always welcome

having issues?

We have a Questions and Answer section where you can ask your iOS Development questions to thousands of iOS Developers.

Ask Question

FREE Download!

Get your FREE Swift 2 Cheat Sheet and quick reference guide PDF download when you sign up to SwiftMonthly

Sharing is caring

If you enjoyed this tutorial, please help us and others by sharing using one of the social media buttons below.

Written by:

Senior .net developer by day, iOS developer by night - looking to venture into the world of iOS development and share my thoughts along the way!