TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Oct 2015 |
SPMSupports SPM | ✗ |
Maintained by hirohisa.
Context transitioning’s animation manager for iOS written in Swift. Create animation tasks for each layer’s animation and deliver tasks on Union.Delegate.
dependencies
.If you prefer not to use either of the aforementioned dependency managers, you can integrate Union into your project manually.
Open up Terminal, cd
into your top-level project directory, and run the following command “if” your project is not initialized as a git repository:
Add ImageLoader as a git submodule by running the following command:
$ git submodule add https://github.com/TransitionKit/Union.git
I create sample animation with Union, it is like “User-Profile-Interface-Animation” from dribbble.com.
see project.
Unit of animation is Union.Task. There are two ways to create it:
Init with layer and animation
Most cases is this pattern
let animation = Animation(layer:layer, animation:animation)
Init with delay time and completion block
Use when there is a process not an animation
let animation = Animation(delay: 0.3) {
self.view.insertSubview(self.imageView, aboveSubview: self.backgroundView)
}
Union.Animation class:
public class Animation {
// public property
public var delay: NSTimeInterval = 0.0 // animation start after delay time
public var completion: () -> () = {} // block called when animation is finished
public init(layer: CALayer, animation: CAPropertyAnimation) {
self.layer = layer
self.animation = animation
}
public init (delay: NSTimeInterval, completion: () -> ()) {
self.delay = delay
self.completion = completion
}
}
Call animation tasks from UIViewControllers with Union.Delegate protocol.
Union.Delegate protocol:
public protocol Delegate {
func animationsBeforeTransitionTo(viewController: UIViewController) -> [Animation]
func animationsDuringTransitionFrom(viewController: UIViewController) -> [Animation]
}
animationsBeforeTransitionTo(viewController: UIViewController) -> [Animation]
Transition begin after these tasks are completed and this method is called by UIViewController
displayed only.
animationsDuringTransitionFrom(viewController: UIViewController) -> [Animation]
Tasks called by two UIViewController
s start during transition. context.completeTransition(true)
is called after all tasks are completed.
extension ViewController: UINavigationControllerDelegate {
func navigationController(navigationController: UINavigationController,
animationControllerForOperation operation: UINavigationControllerOperation,
fromViewController fromVC: UIViewController,
toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return Union.Navigator.animate()
}
}
extension ViewController: UIViewControllerTransitioningDelegate {
func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return Union.Presentor.animate()
}
}
Union is available under the MIT license.