@@ -38,7 +38,9 @@ final class ElementOrderViewController: AccessibilityViewController {
38
38
// MARK: - Life Cycle
39
39
40
40
init ( configurations: [ ViewConfiguration ] ) {
41
- views = configurations. enumerated ( ) . map { index, configuration in
41
+ super. init ( nibName: nil , bundle: nil )
42
+
43
+ rootView. views = configurations. enumerated ( ) . map { index, configuration in
42
44
let view : UIView
43
45
switch configuration {
44
46
case . element:
@@ -64,8 +66,6 @@ final class ElementOrderViewController: AccessibilityViewController {
64
66
65
67
return ( view, configuration)
66
68
}
67
-
68
- super. init ( nibName: nil , bundle: nil )
69
69
}
70
70
71
71
@available ( * , unavailable)
@@ -75,34 +75,53 @@ final class ElementOrderViewController: AccessibilityViewController {
75
75
76
76
// MARK: - Private Properties
77
77
78
- private let views : [ ( UIView , ViewConfiguration ) ]
78
+ private var rootView : View {
79
+ return view as! View
80
+ }
79
81
80
82
// MARK: - UIViewController
81
83
82
- override func viewDidLoad( ) {
83
- super. viewDidLoad ( )
84
-
85
- views. forEach { view. addSubview ( $0. 0 ) }
84
+ override func loadView( ) {
85
+ view = View ( )
86
86
}
87
87
88
- override func viewDidLayoutSubviews( ) {
89
- super. viewDidLayoutSubviews ( )
88
+ }
90
89
91
- views. forEach {
92
- let ( view, configuration) = $0
93
- switch configuration {
94
- case let . element( offset) :
95
- view. align (
96
- . center,
97
- withSuperviewPosition: . center,
98
- horizontalOffset: offset. horizontal,
99
- verticalOffset: offset. vertical
100
- )
101
-
102
- case . container, . viewWithAccessibleSubviews:
103
- view. alignToSuperview ( . center)
90
+ // MARK: -
91
+
92
+ private extension ElementOrderViewController {
93
+
94
+ final class View : UIView {
95
+
96
+ // MARK: - Public Properties
97
+
98
+ var views : [ ( UIView , ViewConfiguration ) ] = [ ] {
99
+ didSet {
100
+ oldValue. forEach { $0. 0 . removeFromSuperview ( ) }
101
+ views. forEach { addSubview ( $0. 0 ) }
104
102
}
105
103
}
104
+
105
+ // MARK: - UIView
106
+
107
+ override func layoutSubviews( ) {
108
+ views. forEach {
109
+ let ( view, configuration) = $0
110
+ switch configuration {
111
+ case let . element( offset) :
112
+ view. align (
113
+ . center,
114
+ withSuperviewPosition: . center,
115
+ horizontalOffset: offset. horizontal,
116
+ verticalOffset: offset. vertical
117
+ )
118
+
119
+ case . container, . viewWithAccessibleSubviews:
120
+ view. alignToSuperview ( . center)
121
+ }
122
+ }
123
+ }
124
+
106
125
}
107
126
108
127
}
0 commit comments