CNUpSlideCardPresentationController.swift
1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// CNUpSlideCardPresentationController.swift
// metaCode
//
// Created by zx on 2023/10/16.
//
import UIKit
class CNUpSlideCardPresentationController: UIPresentationController {
private lazy var blurView = UIVisualEffectView(effect: nil)
override var shouldRemovePresentersView: Bool {
return false
}
override func presentationTransitionWillBegin() {
let container = containerView!
blurView.translatesAutoresizingMaskIntoConstraints = false
container.addSubview(blurView)
blurView.edges(to: container)
blurView.alpha = 0.0
presentingViewController.beginAppearanceTransition(false, animated: false)
presentedViewController.transitionCoordinator!.animate(alongsideTransition: { (ctx) in
self.blurView.effect = UIBlurEffect(style: .light)
self.blurView.alpha = 1
}) { (ctx) in }
}
override func presentationTransitionDidEnd(_ completed: Bool) {
presentingViewController.endAppearanceTransition()
}
override func dismissalTransitionWillBegin() {
presentingViewController.beginAppearanceTransition(true, animated: true)
presentedViewController.transitionCoordinator!.animate(alongsideTransition: { (ctx) in
self.blurView.alpha = 0.0
}, completion: nil)
}
override func dismissalTransitionDidEnd(_ completed: Bool) {
presentingViewController.endAppearanceTransition()
if completed {
blurView.removeFromSuperview()
}
}
}