-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRZDebugMenuRootViewController.m
More file actions
131 lines (108 loc) · 4.6 KB
/
RZDebugMenuRootViewController.m
File metadata and controls
131 lines (108 loc) · 4.6 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
//
// RZDebugMenuRootViewController.m
// RZDebugMenuDemo
//
// Created by Clayton Rieck on 6/2/14.
// Copyright (c) 2014 Raizlabs. All rights reserved.
//
#import "RZDebugMenuRootViewController.h"
#import <RZDebugMenu/RZDebugMenu.h>
#import <RZDebugMenu/RZDebugMenuSettings.h>
@interface RZDebugMenuRootViewController ()
@end
@implementation RZDebugMenuRootViewController
- (void)dealloc
{
[[RZDebugMenuSettings sharedSettings] removeObserver:self forKeyPath:@"reset_toggle"];
[[RZDebugMenuSettings sharedSettings] removeObserver:self forKeyPath:@"slider_preference"];
[[RZDebugMenuSettings sharedSettings] removeObserver:self forKeyPath:@"name_preference"];
[[RZDebugMenuSettings sharedSettings] removeObserver:self forKeyPath:@"circle_choice"];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor blueColor];
self.circle = [[UIView alloc] initWithFrame:CGRectMake(100, 200, 100, 100)];
self.testTextField = [[UITextField alloc] initWithFrame:CGRectMake(50, 100, 100, 50)];
self.testTextField.text = @"0";
self.testTextField.textColor = [UIColor whiteColor];
self.testTextField.enabled = NO;
[self.view addSubview:self.testTextField];
// For specific observation of particular debug settings, you can use standard KVO (or any other syntactic sugar on top of it).
[[RZDebugMenuSettings sharedSettings] addObserver:self forKeyPath:@"reset_toggle" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:NULL];
[[RZDebugMenuSettings sharedSettings] addObserver:self forKeyPath:@"slider_preference" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:NULL];
[[RZDebugMenuSettings sharedSettings] addObserver:self forKeyPath:@"name_preference" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:NULL];
[[RZDebugMenuSettings sharedSettings] addObserver:self forKeyPath:@"circle_choice" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:NULL];
UIGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureRecognizerFired:)];
[self.view addGestureRecognizer:panGestureRecognizer];
}
- (void)panGestureRecognizerFired:(id)sender
{
if ( self.presentedViewController == nil ) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Woah there ...." message:@"You swiped the background view, didn't you?" preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"Yep" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}]];
[self presentViewController:alertController animated:YES completion:nil];
}
}
- (void)changeBackground:(NSNumber *)toggleValue
{
if ( [toggleValue boolValue] ) {
self.view.backgroundColor = [UIColor purpleColor];
}
else {
self.view.backgroundColor = [UIColor blueColor];
}
}
- (void)changeValue:(NSNumber *)sliderValue
{
self.testTextField.text = [sliderValue stringValue];
}
- (void)changeNavTitle:(NSString *)newTitle
{
self.title = newTitle;
}
- (void)changeMultiValue:(NSNumber *)newValue
{
self.circle.layer.cornerRadius = 50;
switch ( [newValue intValue] ) {
case 1: {
self.circle.backgroundColor = [UIColor greenColor];
[self.view addSubview:self.circle];
break;
}
case 2: {
self.circle.backgroundColor = [UIColor blueColor];
[self.view addSubview:self.circle];
break;
}
case 3: {
self.circle.backgroundColor = [UIColor redColor];
[self.view addSubview:self.circle];
break;
}
default:
[self.circle removeFromSuperview];
break;
}
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
id newValue = [change objectForKey:NSKeyValueChangeNewKey];
if ( [keyPath isEqualToString:@"reset_toggle"] ) {
[self changeBackground:newValue];
}
else if ( [keyPath isEqualToString:@"slider_preference"] ) {
[self changeValue:newValue];
}
else if ( [keyPath isEqualToString:@"name_preference"] ) {
[self changeNavTitle:newValue];
}
else if ( [keyPath isEqualToString:@"circle_choice"] ) {
[self changeMultiValue:newValue];
}
else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
@end