123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- 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 = .forwards
- 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)
- }
- }
|