AICustomViewControllerTransition 1.1.2

AICustomViewControllerTransition 1.1.2

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

Maintained by cocoatoucher.



  • By
  • cocoatoucher

AICustomViewControllerTransition

Easy and tidy way for creating custom UIViewController transitions for iOS

Create view controller transitions with no limits and without the complexity of implementing UIViewControllerAnimatedTransitioning protocol or subclassing UIPercentDrivenInteractiveTransition. You just need to use provided transitioningDelegate closure callbacks and provide your UIView animation code.

Drag Down icon used in examples and screenshots is by IconMafia from thenounproject.com (https://thenounproject.com/search/?q=drag&i=463918)

Requirements

  • iOS 8.1+
  • Xcode 8 (Use pod version 1.0.3 for Xcode 7)

Installation

Embedded frameworks require a minimum deployment target of iOS 8.1

To use with a project targeting iOS 7, or if you don’t want to use CocoaPods you must include the AICustomViewControllerTransition.swift source file directly in your project.


Usage

1. Create a custom transitioning delegate object

  • SimpleTransitioningDelegate

If you don’t want your transition to be interactive

let mySimpleTransitioningDelegate = SimpleTransitioningDelegate()
  • InteractiveTransitioningDelegate

If you want your transition to be interactive as well. Includes all the functionality of SimpleTransitioningDelegate

let myInteractiveTransitioningDelegate = InteractiveTransitioningDelegate()

2. Assign animation closures to your transitioning delegate

  • transitionPresent

Animate transition for presenting your modal view controller. See SimpleTransitionViewController example in the Example project.

mySimpleTransitioningDelegate.transitionPresent = { [weak self] (fromViewController: UIViewController, toViewController: UIViewController, containerView: UIView, transitionType: TransitionType, completion: @escaping () -> Void) in

    UIView.animate(withDuration: animationDuration, animations: {
        // Your custom presentation animation here
        // Use provided viewController views to animate
    }, completion: { (finished) in
        // Do't forget to execute completion closure
        completion()
    })
}
  • transitionDismiss

Animate transition for dismissing your modal view controller. See SimpleTransitionViewController example in the Example project.

mySimpleTransitioningDelegate.transitionDismiss = { [weak self] (fromViewController: UIViewController, toViewController: UIViewController, containerView: UIView, transitionType: TransitionType, completion: @escaping () -> Void) in

    UIView.animate(withDuration: animationDuration, animations: {
        // Your custom dismissal animation here
        // Use provided viewController views to animate
    }, completion: { (finished) in
        completion()
    })
}
  • transitionPercentPresent

Animate percent driven interactive transition for presenting your modal view controller. See PanToViewTransitionViewController and ExpandingCellsTableViewController examples in the Example project.

myInteractiveTransitioningDelegate.transitionPercentPresent = {[weak self] (fromViewController: UIViewController, toViewController: UIViewController, percentage: CGFloat, containerView: UIView) in
    // Animate your view controllers using provided percentage
    // Because the transition is progressive, you probably don't need an animation block here
}
  • transitionPercentDismiss

Animate percent driven interactive transition for dismissing your modal view controller. See PanToViewTransitionViewController and ExpandingCellsTableViewController examples in the Example project.

myInteractiveTransitioningDelegate.transitionPercentDismiss = {[weak self] (fromViewController: UIViewController, toViewController: UIViewController, percentage: CGFloat, containerView: UIView) in
    // Animate your view controllers using provided percentage
    // Because the transition is progressive, you probably don't need an animation block here
}

3. Begin, update and finalize a percent driven interactive transition

Use below methods if you are using an InteractiveTransitioningDelegate as your transitioning delegate. See PanToViewTransitionViewController and ExpandingCellsTableViewController examples in the Example project.

  • beginPresenting(viewController:fromViewController:) or beginDismissing(viewController:)

Begin presenting your modal view controller, usually in the callback method for a gesture recognizer that your user interacts with.

myInteractiveTransitioningDelegate.beginPresenting(viewController:myModalViewController, fromViewController:self)
  • update(_:)

Update the percentage of your transition, usually in the callback method for a gesture recognizer that your user interacts with.

myInteractiveTransitioningDelegate.update(percentage)
  • finalizeInteractiveTransition(isTransitionCompleted:)

End presenting or dismissing an interactive transition.

myInteractiveTransitioningDelegate.finalizeInteractiveTransition(isTransitionCompleted:true)

4. Present your view controller as usual

If you are not presenting your view controller in an interactive way, present your view controller as usual. Even if you are using an InteractiveTransitioningDelegate you can still choose to present or dismiss your view controller automatically without a progressive interaction from user, e.g. user taps the button only once. See PanToViewTransitionViewController in Example project.

myModalViewController.modalPresentationStyle = .Custom
myModalViewController.transitioningDelegate = myInteractiveTransitioningDelegate //or mySimpleTransitioningDelegate
self.presentViewController(self.detailViewController, animated: true, completion: nil)

Documentation

http://cocoadocs.org/docsets/AICustomViewControllerTransition/

License

AICustomViewControllerTransition is released under the MIT license. See LICENSE for details.

youtube, fancy