|
//
// AppearAnimatedTransitioning.swift
// PaiAi
//
// Created by ffib on 2018/12/16.
// Copyright © 2018 yb. All rights reserved.
//
import UIKit
class AppearAnimatedTransitioning: NSObject, UIViewControllerAnimatedTransitioning {
weak var delegate: AlertAnimatorDelegate?
fileprivate var animator: AlertViewAnimatable
init(animator: AlertViewAnimatable) {
self.animator = animator
super.init()
}
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.3
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let toVC = transitionContext.viewController(forKey: .to),
let toView = toVC.view,
let contentView = delegate?.getContentView() else { return }
transitionContext.containerView.addSubview(toView)
let duration = transitionDuration(using: transitionContext)
animator.toViewPresentedAnimation(duration: duration, in: toView)
animator.contentViewAppearAnimation(duration: duration, in: contentView)
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + duration) {
let isCancelled = transitionContext.transitionWasCancelled
transitionContext.completeTransition(!isCancelled)
}
}
}
|