-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathMMExampleCenterTableViewController.m
More file actions
416 lines (367 loc) · 17.2 KB
/
MMExampleCenterTableViewController.m
File metadata and controls
416 lines (367 loc) · 17.2 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
// Copyright (c) 2013 Mutual Mobile (http://mutualmobile.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import "MMExampleCenterTableViewController.h"
#import "MMExampleDrawerVisualStateManager.h"
#import "UIViewController+MMDrawerController.h"
#import "MMDrawerBarButtonItem.h"
#import "MMLogoView.h"
#import "MMCenterTableViewCell.h"
#import "MMExampleLeftSideDrawerViewController.h"
#import "MMExampleRightSideDrawerViewController.h"
#import "MMNavigationController.h"
#import <QuartzCore/QuartzCore.h>
typedef NS_ENUM(NSInteger, MMCenterViewControllerSection){
MMCenterViewControllerSectionStatusBarBackgroundState,
MMCenterViewControllerSectionLeftViewState,
MMCenterViewControllerSectionLeftDrawerAnimation,
MMCenterViewControllerSectionRightViewState,
MMCenterViewControllerSectionRightDrawerAnimation,
};
@interface MMExampleCenterTableViewController ()
@end
@implementation MMExampleCenterTableViewController
- (id)init
{
self = [super init];
if (self) {
[self setRestorationIdentifier:@"MMExampleCenterControllerRestorationKey"];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
[self.tableView setDelegate:self];
[self.tableView setDataSource:self];
[self.view addSubview:self.tableView];
[self.tableView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
UITapGestureRecognizer * doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
[doubleTap setNumberOfTapsRequired:2];
[self.view addGestureRecognizer:doubleTap];
UITapGestureRecognizer * twoFingerDoubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerDoubleTap:)];
[twoFingerDoubleTap setNumberOfTapsRequired:2];
[twoFingerDoubleTap setNumberOfTouchesRequired:2];
[self.view addGestureRecognizer:twoFingerDoubleTap];
[self setupLeftMenuButton];
[self setupRightMenuButton];
if(OSVersionIsAtLeastiOS7()){
UIColor * barColor = [UIColor
colorWithRed:217.0/255.0
green:219.0/255.0
blue:220.0/255.0
alpha:1.0];
[self.navigationController.navigationBar setBarTintColor:barColor];
}
else {
UIColor * barColor = [UIColor
colorWithRed:78.0/255.0
green:156.0/255.0
blue:206.0/255.0
alpha:1.0];
[self.navigationController.navigationBar setTintColor:barColor];
}
MMLogoView * logo = [[MMLogoView alloc] initWithFrame:CGRectMake(0, 0, 29, 31)];
[self.navigationItem setTitleView:logo];
[self.navigationController.view.layer setCornerRadius:10.0f];
UIView *backView = [[UIView alloc] init];
[backView setBackgroundColor:[UIColor colorWithRed:208.0/255.0
green:208.0/255.0
blue:208.0/255.0
alpha:1.0]];
[self.tableView setBackgroundView:backView];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
NSLog(@"Center will appear");
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
NSLog(@"Center did appear");
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
NSLog(@"Center will disappear");
}
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
NSLog(@"Center did disappear");
}
-(void)setupLeftMenuButton{
MMDrawerBarButtonItem * leftDrawerButton = [[MMDrawerBarButtonItem alloc] initWithTarget:self action:@selector(leftDrawerButtonPress:)];
[self.navigationItem setLeftBarButtonItem:leftDrawerButton animated:YES];
}
-(void)setupRightMenuButton{
MMDrawerBarButtonItem * rightDrawerButton = [[MMDrawerBarButtonItem alloc] initWithTarget:self action:@selector(rightDrawerButtonPress:)];
[self.navigationItem setRightBarButtonItem:rightDrawerButton animated:YES];
}
-(void)contentSizeDidChange:(NSString *)size{
[self.tableView reloadData];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 5;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
switch (section) {
case MMCenterViewControllerSectionLeftDrawerAnimation:
case MMCenterViewControllerSectionRightDrawerAnimation:
return 5;
case MMCenterViewControllerSectionLeftViewState:
case MMCenterViewControllerSectionRightViewState:
return 1;
case MMCenterViewControllerSectionStatusBarBackgroundState:
return 3;
default:
return 0;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[MMCenterTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleGray];
}
UIColor * selectedColor = [UIColor
colorWithRed:1.0/255.0
green:15.0/255.0
blue:25.0/255.0
alpha:1.0];
UIColor * unselectedColor = [UIColor
colorWithRed:79.0/255.0
green:93.0/255.0
blue:102.0/255.0
alpha:1.0];
switch (indexPath.section) {
case MMCenterViewControllerSectionStatusBarBackgroundState:
if(self.mm_drawerController.statusBarBackgroundViewMode == indexPath.row){
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
[cell.textLabel setTextColor:selectedColor];
}
else {
[cell setAccessoryType:UITableViewCellAccessoryNone];
[cell.textLabel setTextColor:unselectedColor];
}
switch (indexPath.row) {
case MMStatusBarBackgroundViewModeNone:
[cell.textLabel setText:@"None"];
break;
case MMStatusBarBackgroundViewModeOpaque:
[cell.textLabel setText:@"Opaque"];
break;
case MMStatusBarBackgroundViewModeVariable:
[cell.textLabel setText:@"Variable"];
break;
default:
break;
}
break;
case MMCenterViewControllerSectionLeftDrawerAnimation:
case MMCenterViewControllerSectionRightDrawerAnimation:{
MMDrawerAnimationType animationTypeForSection;
if(indexPath.section == MMCenterViewControllerSectionLeftDrawerAnimation){
animationTypeForSection = [[MMExampleDrawerVisualStateManager sharedManager] leftDrawerAnimationType];
}
else {
animationTypeForSection = [[MMExampleDrawerVisualStateManager sharedManager] rightDrawerAnimationType];
}
if(animationTypeForSection == indexPath.row){
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
[cell.textLabel setTextColor:selectedColor];
}
else {
[cell setAccessoryType:UITableViewCellAccessoryNone];
[cell.textLabel setTextColor:unselectedColor];
}
switch (indexPath.row) {
case MMDrawerAnimationTypeNone:
[cell.textLabel setText:@"None"];
break;
case MMDrawerAnimationTypeSlide:
[cell.textLabel setText:@"Slide"];
break;
case MMDrawerAnimationTypeSlideAndScale:
[cell.textLabel setText:@"Slide and Scale"];
break;
case MMDrawerAnimationTypeSwingingDoor:
[cell.textLabel setText:@"Swinging Door"];
break;
case MMDrawerAnimationTypeParallax:
[cell.textLabel setText:@"Parallax"];
break;
default:
break;
}
break;
}
case MMCenterViewControllerSectionLeftViewState:{
[cell.textLabel setText:@"Enabled"];
if(self.mm_drawerController.leftDrawerViewController){
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
[cell.textLabel setTextColor:selectedColor];
}
else{
[cell setAccessoryType:UITableViewCellAccessoryNone];
[cell.textLabel setTextColor:unselectedColor];
}
break;
}
case MMCenterViewControllerSectionRightViewState:{
[cell.textLabel setText:@"Enabled"];
if(self.mm_drawerController.rightDrawerViewController){
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
[cell.textLabel setTextColor:selectedColor];
}
else{
[cell setAccessoryType:UITableViewCellAccessoryNone];
[cell.textLabel setTextColor:unselectedColor];
}
break;
}
default:
break;
}
return cell;
}
-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
switch (section) {
case MMCenterViewControllerSectionStatusBarBackgroundState:
return @"Status Bar Background View Mode";
case MMCenterViewControllerSectionLeftDrawerAnimation:
return @"Left Drawer Animation";
case MMCenterViewControllerSectionRightDrawerAnimation:
return @"Right Drawer Animation";
case MMCenterViewControllerSectionLeftViewState:
return @"Left Drawer";
case MMCenterViewControllerSectionRightViewState:
return @"Right Drawer";
default:
return nil;
}
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MMExampleCenterTableViewController * center;
UINavigationController * nav;
switch (indexPath.section) {
case MMCenterViewControllerSectionStatusBarBackgroundState:
[self.mm_drawerController setStatusBarBackgroundViewMode:indexPath.row];
center = [[MMExampleCenterTableViewController alloc] init];
nav = [[MMNavigationController alloc] initWithRootViewController:center];
self.mm_drawerController.centerViewController = nav;
[tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationNone];
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
break;
case MMCenterViewControllerSectionLeftDrawerAnimation:
case MMCenterViewControllerSectionRightDrawerAnimation:{
if(indexPath.section == MMCenterViewControllerSectionLeftDrawerAnimation){
[[MMExampleDrawerVisualStateManager sharedManager] setLeftDrawerAnimationType:indexPath.row];
}
else {
[[MMExampleDrawerVisualStateManager sharedManager] setRightDrawerAnimationType:indexPath.row];
}
[tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationNone];
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
break;
}
case MMCenterViewControllerSectionLeftViewState:
case MMCenterViewControllerSectionRightViewState:{
UIViewController * sideDrawerViewController;
MMDrawerSide drawerSide = MMDrawerSideNone;
if(indexPath.section == MMCenterViewControllerSectionLeftViewState){
sideDrawerViewController = self.mm_drawerController.leftDrawerViewController;
drawerSide = MMDrawerSideLeft;
}
else if(indexPath.section == MMCenterViewControllerSectionRightViewState){
sideDrawerViewController = self.mm_drawerController.rightDrawerViewController;
drawerSide = MMDrawerSideRight;
}
if(sideDrawerViewController){
[self.mm_drawerController
closeDrawerAnimated:YES
completion:^(BOOL finished) {
if(drawerSide == MMDrawerSideLeft){
[self.mm_drawerController setLeftDrawerViewController:nil];
[self.navigationItem setLeftBarButtonItems:nil animated:YES];
}
else if(drawerSide == MMDrawerSideRight){
[self.mm_drawerController setRightDrawerViewController:nil];
[self.navigationItem setRightBarButtonItem:nil animated:YES];
}
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}];
}
else {
if(drawerSide == MMDrawerSideLeft){
UIViewController * vc = [[MMExampleLeftSideDrawerViewController alloc] init];
if(OSVersionIsAtLeastiOS7()){
UINavigationController * navC = [[MMNavigationController alloc] initWithRootViewController:vc];
[self.mm_drawerController setLeftDrawerViewController:navC];
}
else {
[self.mm_drawerController setLeftDrawerViewController:vc];
}
[self setupLeftMenuButton];
}
else if(drawerSide == MMDrawerSideRight){
UIViewController * vc = [[MMExampleRightSideDrawerViewController alloc] init];
if(drawerSide == MMDrawerSideLeft){
UINavigationController * navC = [[MMNavigationController alloc] initWithRootViewController:vc];
[self.mm_drawerController setRightDrawerViewController:navC];
}
else {
[self.mm_drawerController setRightDrawerViewController:vc];
}
[self setupRightMenuButton];
}
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
break;
}
default:
break;
}
}
#pragma mark - Button Handlers
-(void)leftDrawerButtonPress:(id)sender{
[self.mm_drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];
}
-(void)rightDrawerButtonPress:(id)sender{
[self.mm_drawerController toggleDrawerSide:MMDrawerSideRight animated:YES completion:nil];
}
-(void)doubleTap:(UITapGestureRecognizer*)gesture{
[self.mm_drawerController bouncePreviewForDrawerSide:MMDrawerSideLeft completion:nil];
}
-(void)twoFingerDoubleTap:(UITapGestureRecognizer*)gesture{
[self.mm_drawerController bouncePreviewForDrawerSide:MMDrawerSideRight completion:nil];
}
@end