Adding Paging

Paging works by moving the content in units of the width and/or height of the scroll view. The user experience is flipping horizontally through the car images. To accomplish this, each car image must be the width of the scroll view. And because each image is the same width, the size of the content view is the width of the scroll view times the number of images.

Replace setupScrollContents with the code in Listing 6-4.

Listing 6-4 Paging Version of CarImageViewController

- (void)setupScrollContent {     CGFloat scrollWidth = self.view.bounds.size.width;                      // 1     CGFloat totalWidth = scrollWidth * [carImageNames count];               // 2     UIView *carImageContainerView = [[UIView ...

Get Learning iOS Development: A Hands-on Guide to the Fundamentals of iOS Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.