CNLiveModalPresentationViewController.swift
1.81 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
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// CNLiveModalPresentationViewController.swift
// metaCode
//
// Created by zx on 2023/11/16.
//
import Foundation
typealias completionBlock = (_ finished:Bool)->Void
typealias confirmActionBlock = ()->Void
class CNLiveModalPresentationViewController:UIViewController{
var confirmBlock:confirmActionBlock?
lazy var contentView :UIView = {
let contentView = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
return contentView
}()
lazy var bgView :UIView = {
let bgView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.width, height: self.view.height))
bgView.backgroundColor = .black
bgView.alpha = 0.2
return bgView
}()
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .clear
self.view.addSubview(self.bgView)
self.view.addSubview(self.contentView)
}
@objc func cancelButtonAction(){
self.hidingAnimationWithCompletion { finished in
}
}
@objc func confirmButtonAction(){
if ((self.confirmBlock?()) != nil){
self.confirmBlock!()
}
}
func showingAnimationWithCompletion(completion:@escaping completionBlock){
UIView.animate(withDuration: 0.3, delay: 0.0, options: .curveEaseOut) {
self.contentView.top = (self.view.height-self.contentView.height)/2
} completion: { finished in
completion(finished)
}
}
func hidingAnimationWithCompletion(completion:@escaping completionBlock){
UIView.animate(withDuration: 0.3, delay: 0.0, options: .curveEaseOut) {
self.contentView.top = self.view.height
} completion: { finished in
completion(finished)
self.view.removeFromSuperview()
}
}
}