Brak opisu

AlertViewAnimatable.swift 2.0KB

    // // AlertAnimator.swift // PaiAi // // Created by ffib on 2018/12/17. // Copyright © 2018 yb. All rights reserved. // import UIKit protocol AlertViewAnimatable { func toViewPresentedAnimation(duration: TimeInterval, in view: UIView) func fromViewPresentingAnimation(duration: TimeInterval, in view: UIView) func contentViewAppearAnimation(duration: TimeInterval, in view: UIView) func contentViewDisappearAnimation(duration: TimeInterval, in view: UIView) } extension AlertViewAnimatable { func toViewPresentedAnimation(duration: TimeInterval, in view: UIView) { 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 view.layer.add(animation, forKey: nil) } func fromViewPresentingAnimation(duration: TimeInterval, in view: UIView) { let animation = CABasicAnimation(keyPath: "backgroundColor") animation.duration = duration animation.isRemovedOnCompletion = false animation.fillMode = kCAFillModeForwards animation.toValue = UIColor(red: 52 / 255, green: 52 / 255, blue: 52 / 255, alpha: 0).cgColor animation.fromValue = UIColor(red: 52 / 255, green: 52 / 255, blue: 52 / 255, alpha: 0.7).cgColor view.layer.add(animation, forKey: nil) } }