9
9
#import " OptionsViewController.h"
10
10
11
11
#import " SwitchCellModel.h"
12
+ #import " SegmentCellModel.h"
12
13
13
14
#import " SwitchCell.h"
14
15
#import " SliderCell.h"
15
16
#import " SegmentCell.h"
16
17
17
- @interface OptionsViewController ()<CellStateChange>{
18
+ #define kHeightSwitchCell 54
19
+ #define kHeightSegmentCell 72
20
+
21
+ @interface OptionsViewController ()<CellStateChange, CellSegmentChange>{
18
22
19
23
ElasticTransition *tm ;
20
24
NSMutableArray *menuItems;
@@ -51,29 +55,55 @@ - (void)viewDidLoad {
51
55
52
56
53
57
NSMutableArray *va = [[NSMutableArray alloc ] init ];
54
- [va addObject: [ NSNumber numberWithInt: NONE] ];
55
- [va addObject: [ NSNumber numberWithInt: ROTATE] ];
56
- [va addObject: [ NSNumber numberWithInt: TRANSLATEMID] ];
58
+ [va addObject: @" NONE" ];
59
+ [va addObject: @" ROTATE" ];
60
+ [va addObject: @" TRANSLATE MID " ];
57
61
58
62
59
63
menuItems = [[NSMutableArray alloc ] init ];
60
64
61
65
SwitchCellModel *stickySwitchModel = [[SwitchCellModel alloc ]init];
62
66
stickySwitchModel.name = @" Sticky" ;
63
- stickySwitchModel.on = tm .sticky ;
64
- stickySwitchModel.rowHeigth = 54.0 ;
65
67
stickySwitchModel.type = STICKY;
68
+ stickySwitchModel.on = tm .sticky ;
69
+ stickySwitchModel.rowHeigth = kHeightSwitchCell ;
66
70
stickySwitchModel.delegate = self;
67
71
[menuItems addObject: stickySwitchModel];
68
72
69
73
SwitchCellModel *shadowSwitchModel = [[SwitchCellModel alloc ]init];
70
74
shadowSwitchModel.name = @" Shadow" ;
71
- shadowSwitchModel.on = tm .showShadow ;
72
- shadowSwitchModel.rowHeigth = 54.0 ;
73
75
shadowSwitchModel.type = SHADOW;
76
+ shadowSwitchModel.on = tm .showShadow ;
77
+ shadowSwitchModel.rowHeigth = kHeightSwitchCell ;
74
78
shadowSwitchModel.delegate = self;
75
79
[menuItems addObject: shadowSwitchModel];
76
80
81
+ SegmentCellModel *transformSegmentModel = [[SegmentCellModel alloc ]init];
82
+ transformSegmentModel.name = @" Transform Type" ;
83
+ transformSegmentModel.type = TRANSFORM;
84
+ transformSegmentModel. values = [va copy ];
85
+
86
+ switch (tm .transformType ) {
87
+ case NONE:
88
+ transformSegmentModel.index = 0 ;
89
+ break ;
90
+ case ROTATE:
91
+ transformSegmentModel.index = 1 ;
92
+ break ;
93
+ case TRANSLATEMID:
94
+ case TRANSLATEPULL:
95
+ case TRANSLATEPUSH:
96
+ transformSegmentModel.index = 2 ;
97
+ break ;
98
+
99
+ default :
100
+ break ;
101
+ }
102
+
103
+ transformSegmentModel.rowHeigth = kHeightSegmentCell ;
104
+ transformSegmentModel.delegate = self;
105
+ [menuItems addObject: transformSegmentModel];
106
+
77
107
78
108
for (int i = 0 ; i < menuItems.count ; i++) {
79
109
@@ -100,7 +130,6 @@ -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSI
100
130
case 1 :
101
131
{
102
132
SwitchCellModel *itemModel = (SwitchCellModel *) [menuItems objectAtIndex: indexPath.row];
103
-
104
133
105
134
SwitchCell *switchCell = [tableView dequeueReusableCellWithIdentifier: @" switch" forIndexPath: indexPath];
106
135
switchCell.cellModel = itemModel;
@@ -110,15 +139,17 @@ -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSI
110
139
}
111
140
case 2 :
112
141
{
142
+ SegmentCellModel *itemModel = (SegmentCellModel *) [menuItems objectAtIndex: indexPath.row];
113
143
144
+ SegmentCell *segmentCell = [tableView dequeueReusableCellWithIdentifier: @" segment" forIndexPath: indexPath];
145
+ segmentCell.cellModel = itemModel;
146
+ cell = segmentCell;
114
147
}
115
148
default :
116
149
break ;
117
150
}
118
151
119
-
120
152
return cell;
121
-
122
153
}
123
154
124
155
@@ -129,20 +160,21 @@ -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)
129
160
130
161
-(CGFloat )tableView : (UITableView *)tableView heightForRowAtIndexPath : (NSIndexPath *)indexPath {
131
162
132
-
133
163
NSObject *itemModel = [menuItems objectAtIndex: indexPath.row];
134
164
135
165
if ([[itemModel class ] conformsToProtocol: @protocol (CellDimensionAndTypeDelegate)]) {
136
- NSObject <CellDimensionAndTypeDelegate> *item = (NSObject <CellDimensionAndTypeDelegate> *) itemModel;
166
+ NSObject <CellDimensionAndTypeDelegate> *itemProt = (NSObject <CellDimensionAndTypeDelegate> *) itemModel;
137
167
138
- return item .rowHeigth ;
168
+ return itemProt .rowHeigth ;
139
169
140
170
}else {
141
171
return 0.0 ;
142
172
}
143
173
}
144
174
145
175
176
+ #pragma mark - Listen to table changes
177
+
146
178
-(void )didChangeStateToOn : (BOOL )on AndPropertyRelated : (PropertyRelated)property {
147
179
148
180
switch (property) {
@@ -157,6 +189,26 @@ -(void)didChangeStateToOn:(BOOL)on AndPropertyRelated:(PropertyRelated)property{
157
189
}
158
190
}
159
191
192
+ -(void )didSelcetedTransformIndex : (NSInteger )index AndPropertyRelated : (PropertyRelated)property {
193
+
194
+ if (property == TRANSFORM) {
195
+
196
+ switch (index ) {
197
+ case 0 :
198
+ tm .transformType = NONE;
199
+ break ;
200
+ case 1 :
201
+ tm .transformType = ROTATE;
202
+ break ;
203
+ case 2 :
204
+ tm .transformType = TRANSLATEMID;
205
+ break ;
206
+ default :
207
+ break ;
208
+ }
209
+ }
210
+ }
211
+
160
212
-(UIStatusBarStyle)preferredStatusBarStyle {
161
213
return UIStatusBarStyleLightContent;
162
214
}
0 commit comments