While you could implement this yourself (with custom container view controller in conjunction with UIPanGestureRecognizer
or UIScrollView
), if using iOS 6 and later, the easiest way will be to use a Page View Controller with "scroll" transition style.
Consider this storyboard:
It consists of a page view controller, and two scenes for two pages. Page 1 has a storyboard identifier of one
and a base class of PageOneViewController
. Page 2 has a storyboard identifier of two
and a base class of PageTwoViewController
.
I then wrote a UIPageViewController
subclass (and, perhaps obvious, this is the class I specified for the first scene of the above storyboard), which has the following code:
- (void)viewDidLoad
{
[super viewDidLoad];
self.dataSource = self;
[self setViewControllers:@[[self.storyboard instantiateViewControllerWithIdentifier:@"one"]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
if ([viewController isKindOfClass:[PageOneViewController class]])
return nil;
return [self.storyboard instantiateViewControllerWithIdentifier:@"one"];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
if ([viewController isKindOfClass:[PageTwoViewController class]])
return nil;
return [self.storyboard instantiateViewControllerWithIdentifier:@"two"];
}
You could do this with NIBs, too, but it requires writing more code. If you search for UIPageViewController XIB
and you'll probably get some hits.
If you need to support iOS versions prior to 6.0, you'll have to do the custom container approach with pan gesture or scroll view.