项目介绍:
AZTransitions
https://github.com/azimin/AZTransitions
Make your modal transition with custom animation.
AZTransitions helps you think about creativity, giving specific API methods.
AZTransitions 使用自定义动画进行模态转换。提供具体的API方法。
Visual Example

Installation
-
Add the following to your
Podfileand runpod install
pod 'AZTransitions'
-
or add the following to your
Cartfileand runcarthage update
github "azimin/AZTransitions"
-
or clone as a git submodule,
-
or just copy
AZTransitions/Source/CustomModalTransition.swiftinto your project.
Code Example
To create any custom transition just subclass CustomModalTransition:
class FashionTransition: CustomModalTransition {
override init() {
super.init(duration: 0.5)
}
}
—
Then set as az_modalTransition to nessesary view just before presenting it
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
segue.destination.customModalTransition = FashionTransition()
}
or
func show() {
let viewController = UIViewController()
viewController.az_modalTransition = FashionTransition()
self.present(viewController, animated: true, completion: nil)
}
—
To have custom present animation, just implement performTransition(interactive: Bool) inside your FashionTransition class:
func performTransition(interactive: Bool) {
self.presentedViewController.view.alpha = 0.0
UIView.animate(withDuration: duration, animations: {
self.presentedViewController.view.alpha = 1.0
self.presentingViewController.view.alpha = 0.0
}, completion: { (completed) in
self.presentingViewController.view.alpha = 1.0
self.finishAnimation(completion: nil)
})
}
As you may have guessed, you have different properties. The main ones:
-
duration— transition duration -
presentingViewController— the presenting view controller (bottom one) -
presentedViewController— view controller that is going to be presented (top one)
You can animate them as you want.
