UIPageViewController and custom UISegmentedControl synchronized and animated. Similar to Spotify's "My Music" section.
Please check the .h to see how to customize anything
You should not use the pod in most cases, as they don't allow for customizability. I would recommend dragging the .h and .m files manually into your project
pod 'RKSwipeBetweenViewControllers'
twitter <--- I am a very light twitterer, so I won't spam you
(after five minutes of customization)
Any number of any view controllers should technically work, though it doesn't look great with more than 4
Customizable!
(check the RKSwipeBetweenViewControllers.h for actual customizable features)
(check out the provided AppDelegate to see an example):
Programmatically (preferred)
-
Import RKSwipeBetweenViewControllers.h
#import <RKSwipeBetweenViewControllers/RKSwipeBetweenViewControllers.h>
-
Initialize a UIPageViewController
UIPageViewController *pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
-
Initialize a RKSwipeBetweenViewControllers
RKSwipeBetweenViewControllers *navigationController = [[RKSwipeBetweenViewControllers alloc]initWithRootViewController:pageController];
-
Add all your ViewControllers (in order) to navigationController.viewControllerArray (try to keep it under 5)
[navigationController.viewControllerArray addObjectsFromArray:@[viewController1, viewController2, viewController3]];
-
Use the custom class (or call it as the first controller from app delegate: see below)
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]; self.window.rootViewController = navigationController; [self.window makeKeyAndVisible];
StoryBoard (do not use pods for this one)
-
Drop the file into your project and import RKSwipeBetweenViewControllers.h
#import RKSwipeBetweenViewControllers.h
-
Embed a UIPageViewController inside a UINavigationController. Change the class of the to UINavigationController the custom class (RKSwipeBetweenViewControllers)
-
change the transition style of the pageviewcontroller to scroll (click on the UIPageViewController in storyboard -> attributes inspector -> transition style -> scroll)
-
go to the RKSwipeBetweenViewControllers.m file and use it as your own class now. Add your view controllers to "viewControllerArray". See below for various options.
Programmatically, outside RKSwipeBetweenViewControllers.m (if this navigation bar isn't the first screen that comes up, or if you want to call it from the delegate)
[customNavController.viewControllerArray addObjectsFromArray:@[viewController1, viewController2, viewController3]];
Programmatically, inside RKSwipeBetweenViewControllers.m (most cases if your view controllers are programmatically created)
[viewControllerArray addObjectsFromArray:@[demo,demo2]];
storyboard, inside RKSwipeBetweenViewControllers.m (if your viewcontrollers are on the storyboard, but make sure to give them storyboard IDs)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController* theController = [storyboard instantiateViewControllerWithIdentifier:@"storyboardID"]; [viewControllerArray addObject:theController];
storyboard, outside RKSwipeBetweenViewControllers.m (if your viewcontrollers are on the storyboard, but make sure to give them storyboard IDs)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController* theController = [storyboard instantiateViewControllerWithIdentifier:@"storyboardID"]; [theCustomViewController.viewControllerArray addObject:theController];
Any problems/questions? shoot me a pm
- Working with horizontal layout
- Working with more than 5 pages
- Handful of infrequent bugs
- Better performance when loading pages
- Changing layout away from UINavigationController to allow the bar to be at the bottom
- Bug: adding a MKMapView to a UIViewController in storyboard causes strange visual bug. Adding programmatically is fine
- Crash on load for UITabBarControllers (resolved): #15