- 最简洁的API 实现任何自定义转场动画
- 清晰的Interface
import UIKit
class ScaleTransitionAnimation: FSTransitionAnimationProtocol {
func setToAnimation(_ fromView: UIView, toView: UIView, containerView: UIView, animationComplete: @escaping (() -> ())) {
}
func backToAnimation(_ fromView: UIView, toView: UIView, containerView: UIView, animationComplete: @escaping (() -> ())) {
}
}
下面我们添加一些简单的缩放动画
import UIKit
class ScaleTransitionAnimation: FSTransitionAnimationProtocol {
func setToAnimation(_ fromView: UIView, toView: UIView, containerView: UIView, animationComplete:@escaping (() -> ())) {
containerView.addSubview(toView)
toView.transform = CGAffineTransform.init(scaleX: 0.01, y: 0.01)
UIView.animate(withDuration: 0.6, animations: {
toView.transform = CGAffineTransform.identity
}) { (finish) in
animationComplete()
}
}
func backToAnimation(_ fromView: UIView, toView: UIView, containerView: UIView, animationComplete:@escaping (() -> ())) {
containerView.addSubview(toView)
containerView.addSubview(fromView)
UIView.animate(withDuration: 0.6, animations: {
fromView.transform = CGAffineTransform.init(scaleX: 0.01, y: 0.01)
}) { (finish) in
animationComplete()
}
}
}
@IBAction func onPushAnimation(_ sender: Any) {
let animation = ScaleTransitionAnimation()
let vc = TestViewController.init(nibName: "TestViewController", bundle: nil)
self.fs_pushViewController(vc, animation: animation)
}
注册手势转场
override func viewDidLoad() {
super.viewDidLoad()
self.fs_registerToInteractiveTransition(.right) {[weak self] in
let animation = SliderTransitionAnimation()
let vc = InteractiveViewController.init(nibName: "InteractiveViewController", bundle: nil)
self?.fs_presentViewController(vc, animation: animation)
}
}
注册手势退场
class InteractiveViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
fs_registerBackInteractiveTransition(UIRectEdge.left) {[weak self] in
self?.dismiss(animated: true, completion: nil)
}
}
}