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)
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.
- 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()
- 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
}
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)
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)
http://cocoadocs.org/docsets/AICustomViewControllerTransition/
AICustomViewControllerTransition is released under the MIT license. See LICENSE for details.
youtube, fancy