-
Notifications
You must be signed in to change notification settings - Fork 0
/
KDBManager.m
108 lines (91 loc) · 2.9 KB
/
KDBManager.m
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
#include "KDBManager.h"
#include "KDBOverlayView.h"
#define NSLog(...) [KDBManager.sharedInstance logString:[NSString stringWithFormat:__VA_ARGS__] file:__FILE__ line:__LINE__]
#define kViewframeWidth UIScreen.mainScreen.bounds.size.width/2
#define kViewframeHeight UIScreen.mainScreen.bounds.size.height/3
@implementation KDBManager {
@private
UIView *_overlayView;
}
@synthesize overlayView = _overlayView;
@synthesize textView = _textView;
@synthesize textQueue = _textQueue;
@synthesize open = _open;
- (instancetype)init
{
self = [super init];
if (self)
{
_textQueue = @"";
}
return self;
}
+ (instancetype)sharedInstance
{
static id _sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^
{
_sharedInstance = [[self alloc] init];
});
return _sharedInstance;
}
- (UIView *)overlayView
{
if (!_overlayView) {
_overlayView = [[KDBOverlayView alloc] initWithFrame:CGRectMake(0,0,600,400)];
[_overlayView addSubview:[self textView]];
_overlayView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.6];
_overlayView.layer.cornerRadius = 10;
}
return _overlayView;
}
- (void)setupOverlayView
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
self.overlayView.frame = CGRectMake(screenWidth - 20, 80, kViewframeWidth, kViewframeHeight);
UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleTap:)];
[_overlayView addGestureRecognizer:singleFingerTap];
}
- (void)handleTap:(UITapGestureRecognizer *)recognizer
{
if (_open)
{
_open = NO;
[UIView animateWithDuration:0.2 animations:^{
_overlayView.transform = CGAffineTransformTranslate(_overlayView.transform, kViewframeWidth, 0);
}];
}
else
{
_open = YES;
[UIView animateWithDuration:0.2 animations:^{
_overlayView.transform = CGAffineTransformTranslate(_overlayView.transform, -kViewframeWidth, 0);
}];
}
}
- (UITextView *)textView
{
if (!_textView) {
_textView = [[UITextView alloc] initWithFrame:CGRectMake(20,20,kViewframeWidth-40,kViewframeHeight-40)];
_textView.text = _textQueue;
_textView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0];
_textView.editable = NO;
}
return _textView;
}
-(void)logString:(NSString *)string file:(char *)file line:(int)line
{
NSString *displayString = [NSString stringWithFormat:@"%s:%d - %@", file, line, string];
if (_textView) {
_textView.text = [NSString stringWithFormat:@"%@%@\n", _textView.text, displayString];
}
else
{
_textQueue = [NSString stringWithFormat:@"%@%@\n", _textQueue, displayString];
}
}
@end