-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRadarView.m
145 lines (124 loc) · 5.28 KB
/
RadarView.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
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
#import "RadarView.h"
#import "QuadrantView.h"
#import "CircleView.h"
#import "ItemView.h"
#import "AppConstants.h"
@implementation RadarView
@synthesize radar;
@synthesize quadrantViews;
@synthesize innerRadius,outerRadius;
@synthesize searchkey;
- (id)initWithFrame:(CGRect)frame WithRadar:(Radar*)newRadar {
self = [super initWithFrame:frame];
if (self) {
self.radar = newRadar;
self.innerRadius=0.0;
self.outerRadius=400.0;
self.searchkey = @"";
self.quadrantViews = [[NSMutableArray alloc] init];
}
return self;
}
-(void) updateWithRadar:(Radar*)newRadar {
self.radar = newRadar;
self.quadrantViews = [[NSMutableArray alloc] init];
[self addQuadrants];
[self hideCircle:0.0 AndOuter:400.0];
[self showAllItems];
}
-(void) searchRadar:(NSString*) newSearchkey {
self.searchkey = newSearchkey;
[self update];
}
-(void)update {
NSString *newSearchkey = [self.searchkey stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet] ];
newSearchkey = [newSearchkey lowercaseString];
for(QuadrantView *quadrantView in self.quadrantViews){
NSArray *subViews = quadrantView.subviews;
for(ItemView *subView in subViews){
NSInteger ratioRadius = RADAR_RATIO*subView.radius;
if(ratioRadius > self.innerRadius*RADAR_RATIO && ratioRadius < self.outerRadius*RADAR_RATIO) {
if([self.searchkey length] > 0) {
NSString *blipName = [subView blipName];
NSString *blipDesc = [subView description];
blipName = [blipName lowercaseString];
if ([blipName rangeOfString:newSearchkey].location == NSNotFound && [blipDesc rangeOfString:newSearchkey].location == NSNotFound) {
[UIView animateWithDuration:0.3 animations:^() {
subView.alpha = 0.0;
}];
} else {
[UIView animateWithDuration:0.3 animations:^() {
subView.alpha = 1.0;
}];
}
}else {
[UIView animateWithDuration:0.3 animations:^() {
subView.alpha = 1.0;
}];
}
}else {
[UIView animateWithDuration:0.3 animations:^() {
subView.alpha = 0.0;
}];
}
}
}
}
-(void) showAllItems {
[self hideCircle:0.0 AndOuter:400.0];
}
-(void) hideCircle:(NSInteger) inRadius AndOuter:(NSInteger) outRadius {
self.innerRadius = inRadius;
self.outerRadius = outRadius;
[self update];
}
-(void) bindQuadrantSingleTap:(QuadrantView*)quadrantView {
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
singleTap.numberOfTapsRequired = 1;
[quadrantView addGestureRecognizer:singleTap];
}
- (void)singleTap:(UITapGestureRecognizer *)recognizer {
QuadrantView *quadrantView = (QuadrantView *)recognizer.view;
[quadrantView resize:self.frame];
}
-(IBAction) displayItemDetails:(UIGestureRecognizer*)sender {
[self.delegate radarView:self didSelectItem:(ItemView*)sender.view];
}
-(void) bindItemTap: (QuadrantView*)quadrantView {
NSArray *subViews = quadrantView.subviews;
for(CircleView *subView in subViews){
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(displayItemDetails:)];
[singleTap setNumberOfTapsRequired:1];
[subView setUserInteractionEnabled:YES];
[subView addGestureRecognizer:singleTap];
}
}
-(QuadrantView*) quadrantOriginX:(CGFloat)x Y:(CGFloat)y Quadrant:(Quadrant*)quadrant{
CGRect screenRect = self.frame;
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
CGPoint origin = CGPointMake(x, y);
CGRect frame = CGRectMake(origin.x, origin.y, screenWidth/2, screenHeight/2);
CGFloat centerX = (x > 0.0 ? 0.0 : screenWidth/2);
CGFloat centerY = (y > 0 ? 0.0 : screenHeight/2);
QuadrantView *quadrantView = [[QuadrantView alloc]initWithFrame:frame
WithCenter:CGPointMake(centerX,centerY)
AndQuadrant:quadrant];
[self bindQuadrantSingleTap:quadrantView];
[self bindItemTap:quadrantView];
[self.quadrantViews addObject:quadrantView];
return quadrantView;
}
-(void) addQuadrants {
NSMutableArray *allQuadrants = [self.radar quadrants];
CGRect screenRect = self.frame;
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
CGFloat midPointX = screenWidth/2;
CGFloat midPointY = screenHeight/2;
[self insertSubview:[self quadrantOriginX:0.0 Y:0 Quadrant:[allQuadrants objectAtIndex:0]] atIndex:1];
[self insertSubview:[self quadrantOriginX:midPointX Y:0 Quadrant:[allQuadrants objectAtIndex:1]] atIndex:1];
[self insertSubview:[self quadrantOriginX:0.0 Y:midPointY Quadrant:[allQuadrants objectAtIndex:2]] atIndex:1];
[self insertSubview:[self quadrantOriginX:midPointX Y:midPointY Quadrant:[allQuadrants objectAtIndex:3]] atIndex:1];
}
@end