1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import UIKit
- class ActionSheetAppearAnimator: NSObject {
- weak var delegate: AlertAnimatorDelegate?
-
- 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)
-
- let animation = CABasicAnimation(keyPath: "backgroundColor")
- animation.duration = duration
- animation.isRemovedOnCompletion = true
- animation.toValue = UIColor(red: 52 / 255,
- green: 52 / 255,
- blue: 52 / 255,
- alpha: 0.7).cgColor
- animation.fromValue = UIColor(red: 52 / 255,
- green: 52 / 255,
- blue: 52 / 255,
- alpha: 0).cgColor
- toView.layer.add(animation, forKey: nil)
-
- let contentAnimation = CATransition()
- contentAnimation.duration = duration
- contentAnimation.type = kCATransitionMoveIn
- contentAnimation.isRemovedOnCompletion = true
- contentAnimation.subtype = kCATransitionFromTop
- contentView.layer.add(contentAnimation, forKey: nil)
-
- DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + duration) {
- let isCancelled = transitionContext.transitionWasCancelled
- transitionContext.completeTransition(!isCancelled)
- }
- }
- }
|