BoardingPass 0.2.1

BoardingPass 0.2.1

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Feb 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Michael Skiba, Raiz Labs, Alex Rouse, Rightpoint CI.



BoardingPass

Navigate Your View Stack with Interactive Swipe Gestures

BoardingPass is a subclass of UINavigationController with interactive push and pop gestures. It offers behaviors similar to UIPageViewController, but with all of the familiar behaviors of navigation controllers, and the ability to easily animate property changes alongside the transitions.

BoardingPass

Features

  • [x] Interactive swipe and pan transitions
  • [x] Navigation Controller push and pop use slide animation as well
  • [x] Supports animating other properties alongside the transition
  • [x] Fine grained control over when the push and pop gestures should be active.

Requirements

  • iOS 9.0+
  • Xcode 8.0+

Manually

  1. Download all of the .swift files in BoardingPass/ and drop them into your project.
  2. Congratulations!

Usage example

To see a complete example of using the gallery, take a look at the sample project.

Simple Boarding

At it’s simplest, a BoardingNavigationController can be initialized with an array of view controllers, and that will allow the user to swipe forward and backward through the navigation stack.

func beginOnboarding() {
    let viewControllers = [
        FirstViewController(),
        SecondViewController(),
        ThirdViewController(),
        ]
    let onboarding = BoardingNavigationController(viewControllersToPresent: viewControllers)
    present(onboarding, animated: true, completion: nil)
}

Controlling Navigation

For finer grained control over navigation, for instance to now allow the user to page backward after viewing the complete boarding stack, a view controller can conform to the BoardingInformation protocol and set a value for nextViewController or previousViewController.

extension ThirdViewController: BoardingInformation {

    var nextViewController: UIViewController? {
        let completed = CompletedViewController()
        return completed
    }

}

By returning a view controller outside of the series of view controllers to present, the BoardingNavigationController will disable the swipe gestures once the user advances to the CompletedViewController.

Going Above and Beyond

To give the boarding stack a more custom look and feel, BoadingPass is designed to make it easy to add animations that run alongside the push and pop presentations. To add a progress slider and a background color alongside navigation animations.

The first step is defining a protocol that each of the presented view controllers is going to conform to, and a delegate protocol that the BoardingInformation subclass is going to conform to to allow the view controllers to communicate back up to the container.

protocol BackgroundColorProvider: class {

    weak var onboardingDelegate: OnboardingViewControllerDelegate? { get set }
    var backgroundColor: UIColor { get }
    var currentProgress: Progress { get }

}
protocol OnboardingViewControllerDelegate: class {

    var backgroundColor: UIColor? { get set }
    var progress: Progress { get set }

}

Next the BackgroundColorProvider can be extended to create a shared function the generate closure to animate the background color and progress indicator.

extension BackgroundColorProvider {

    var animation: (() -> Void) {
        return { [unowned self] in
            self.onboardingDelegate?.backgroundColor = self.backgroundColor
            self.onboardingDelegate?.progress = self.currentProgress
        }
    }

}

Then each class implementing BackgroundColorProvider needs to add a method to viewWillAppear to perform the coordinated animation alongside the current context, with a fallback of executing the animation if there is no context.

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        let factory: AnimationFactory = { [unowned self]  (_, _) in
            return self.animation
        }
        perform(coordinatedAnimations: factory)
    }

Contributing

Issues and pull requests are welcome! Please ensure that you have the latest SwiftLint installed before committing and that there are no style warnings generated when building.

Contributors are expected to abide by the Contributor Covenant Code of Conduct.

License

BoardingPass is available under the MIT license. See the LICENSE file for more info.

Author

Michael Skiba, [email protected] @atelierclkwrk