forked from insidegui/WWDC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModalLoadingView.swift
More file actions
85 lines (63 loc) · 2.41 KB
/
ModalLoadingView.swift
File metadata and controls
85 lines (63 loc) · 2.41 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// ModalLoadingView.swift
// WWDC
//
// Created by Guilherme Rambo on 20/05/17.
// Copyright © 2017 Guilherme Rambo. All rights reserved.
//
import Cocoa
class ModalLoadingView: NSView {
private lazy var backgroundView: NSVisualEffectView = {
let v = NSVisualEffectView()
v.material = .ultraDark
v.appearance = WWDCAppearance.appearance()
v.blendingMode = .withinWindow
v.translatesAutoresizingMaskIntoConstraints = false
v.state = .active
return v
}()
private lazy var spinner: NSProgressIndicator = {
let p = NSProgressIndicator()
p.isIndeterminate = true
p.style = .spinningStyle
p.translatesAutoresizingMaskIntoConstraints = false
return p
}()
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
wantsLayer = true
addSubview(backgroundView)
backgroundView.addSubview(spinner)
backgroundView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
backgroundView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
backgroundView.topAnchor.constraint(equalTo: topAnchor).isActive = true
backgroundView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
spinner.centerXAnchor.constraint(equalTo: backgroundView.centerXAnchor).isActive = true
spinner.centerYAnchor.constraint(equalTo: backgroundView.centerYAnchor).isActive = true
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
static func show(attachedTo view: NSView) -> ModalLoadingView {
let v = ModalLoadingView(frame: view.bounds)
v.show(in: view)
return v
}
func show(in view: NSView) {
alphaValue = 0
autoresizingMask = [.viewWidthSizable, .viewHeightSizable]
spinner.startAnimation(nil)
view.addSubview(self)
NSAnimationContext.runAnimationGroup({ _ in
self.alphaValue = 1
}, completionHandler: nil)
}
func hide() {
NSAnimationContext.runAnimationGroup({ _ in
self.spinner.stopAnimation(nil)
self.alphaValue = 0
}, completionHandler: {
self.removeFromSuperview()
})
}
}