-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathEventDetailLauncher.swift
More file actions
68 lines (57 loc) · 2.67 KB
/
EventDetailLauncher.swift
File metadata and controls
68 lines (57 loc) · 2.67 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
63
64
65
66
67
68
import ECWeekView
import Foundation
import UIKit
class EventDetailLauncher {
lazy var eventView: UIView = {
let view = UIView()
view.backgroundColor = UIColor.white
view.translatesAutoresizingMaskIntoConstraints = false
view.layer.cornerRadius = 10
return view
}()
lazy var blackView: UIView = {
let view = UIView()
view.backgroundColor = UIColor(white: 0, alpha: 0.6)
let tapGuesture = UITapGestureRecognizer(target: self, action: #selector(self.dismiss))
view.addGestureRecognizer(tapGuesture)
return view
}()
var event: ECWeekViewEvent?
@objc func present() {
guard let window = UIApplication.shared.windows.first(where: { $0.isKeyWindow }) else { return }
let height: CGFloat = 100
let buffer: CGFloat = 64
blackView.frame = window.frame
blackView.alpha = 0
window.addSubview(blackView)
eventView.frame = CGRect(x: buffer, y: window.frame.height, width: window.frame.width - (buffer * 2), height: height)
let eventLabel = UILabel(frame: CGRect(x: 16, y: 16, width: eventView.frame.width - 32, height: (eventView.frame.height / 2) - 16))
eventLabel.text = event!.title
eventLabel.font = UIFont.systemFont(ofSize: 20)
eventLabel.textAlignment = .center
let idLabel = UILabel(frame: CGRect(x: 16, y: eventView.frame.height / 2, width: eventView.frame.width - 32, height: eventView.frame.height / 2))
idLabel.text = event!.uuid
idLabel.font = UIFont.systemFont(ofSize: 10)
idLabel.textAlignment = .center
eventView.addSubview(eventLabel)
eventView.addSubview(idLabel)
window.addSubview(eventView)
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
self.eventView.frame.origin.y = (window.frame.height / 2) - (height / 2)
self.blackView.alpha = 0.6
})
}
@objc func dismiss() {
guard let window = UIApplication.shared.windows.first(where: { $0.isKeyWindow }) else { return }
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
self.eventView.frame.origin.y = window.frame.height
self.blackView.alpha = 0
}) { (animationComplete) in
self.eventView.removeFromSuperview()
for subview in self.eventView.subviews {
subview.removeFromSuperview()
}
self.blackView.removeFromSuperview()
}
}
}