-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathSlideController.swift
74 lines (59 loc) · 1.44 KB
/
SlideController.swift
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
import UIKit
open class SlideController: UIViewController {
private var contents = [Content]()
private var animations = [Animatable]()
private var visible = false
public convenience init(contents: [Content]) {
self.init()
add(contents: contents)
}
// MARK: - View lifecycle
open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if !visible {
visible = true
for content in contents {
content.layout()
}
for animation in animations {
animation.play()
}
}
}
open override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
visible = false
}
// MARK: - Navigation
open func goToLeft() {
for case let animation as TransitionAnimation in animations {
animation.reflective = true
}
}
open func goToRight() {
for case let animation as TransitionAnimation in animations {
animation.reflective = false
}
}
}
// MARK: - Public methods
public extension SlideController {
func add(contents: [Content]) {
for content in contents {
add(content: content)
}
}
func add(content: Content) {
contents.append(content)
view.addSubview(content.view)
content.layout()
}
func add(animations: [Animatable]) {
for animation in animations {
add(animation: animation)
}
}
func add(animation: Animatable) {
animations.append(animation)
}
}