17 #pragma mark Setup and teardown |
17 #pragma mark Setup and teardown |
18 |
18 |
19 |
19 |
20 - (id)initWithFrame:(CGRect)frame |
20 - (id)initWithFrame:(CGRect)frame |
21 { |
21 { |
22 if ((self = [super initWithFrame:frame])) { |
22 if ((self = [super initWithFrame:frame])) { |
23 self.userInteractionEnabled = NO; |
23 self.userInteractionEnabled = NO; |
24 self.allowsDragging = NO; |
24 self.allowsDragging = NO; |
25 self.contentMode = UIViewContentModeRedraw; |
25 self.contentMode = UIViewContentModeRedraw; |
26 } |
26 } |
27 return self; |
27 return self; |
28 } |
28 } |
29 |
29 |
30 |
30 |
31 - (void)dealloc |
31 - (void)dealloc |
32 { |
32 { |
33 self.splitViewController = nil; |
33 self.splitViewController = nil; |
34 [super dealloc]; |
|
35 } |
34 } |
36 |
35 |
37 |
36 |
38 #pragma mark - |
37 #pragma mark - |
39 #pragma mark Drawing |
38 #pragma mark Drawing |
40 |
39 |
41 |
40 |
42 - (void)drawRect:(CGRect)rect |
41 - (void)drawRect:(CGRect)rect |
43 { |
42 { |
44 if (splitViewController.dividerStyle == MGSplitViewDividerStyleThin) { |
43 if (splitViewController.dividerStyle == MGSplitViewDividerStyleThin) { |
45 [super drawRect:rect]; |
44 [super drawRect:rect]; |
46 |
45 |
47 } else if (splitViewController.dividerStyle == MGSplitViewDividerStylePaneSplitter) { |
46 } else if (splitViewController.dividerStyle == MGSplitViewDividerStylePaneSplitter) { |
48 // Draw gradient background. |
47 // Draw gradient background. |
49 CGRect bounds = self.bounds; |
48 CGRect bounds = self.bounds; |
50 CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB(); |
49 CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB(); |
51 CGFloat locations[2] = {0, 1}; |
50 CGFloat locations[2] = {0, 1}; |
52 CGFloat components[8] = { 0.988, 0.988, 0.988, 1.0, // light |
51 CGFloat components[8] = { 0.988f, 0.988f, 0.988f, 1.0, // light |
53 0.875, 0.875, 0.875, 1.0 };// dark |
52 0.875, 0.875, 0.875, 1.0 };// dark |
54 CGGradientRef gradient = CGGradientCreateWithColorComponents (rgb, components, locations, 2); |
53 CGGradientRef gradient = CGGradientCreateWithColorComponents (rgb, components, locations, 2); |
55 CGContextRef context = UIGraphicsGetCurrentContext(); |
54 CGContextRef context = UIGraphicsGetCurrentContext(); |
56 CGPoint start, end; |
55 CGPoint start, end; |
57 if (splitViewController.vertical) { |
56 if (splitViewController.vertical) { |
58 // Light left to dark right. |
57 // Light left to dark right. |
59 start = CGPointMake(CGRectGetMinX(bounds), CGRectGetMidY(bounds)); |
58 start = CGPointMake(CGRectGetMinX(bounds), CGRectGetMidY(bounds)); |
60 end = CGPointMake(CGRectGetMaxX(bounds), CGRectGetMidY(bounds)); |
59 end = CGPointMake(CGRectGetMaxX(bounds), CGRectGetMidY(bounds)); |
61 } else { |
60 } else { |
62 // Light top to dark bottom. |
61 // Light top to dark bottom. |
63 start = CGPointMake(CGRectGetMidX(bounds), CGRectGetMinY(bounds)); |
62 start = CGPointMake(CGRectGetMidX(bounds), CGRectGetMinY(bounds)); |
64 end = CGPointMake(CGRectGetMidX(bounds), CGRectGetMaxY(bounds)); |
63 end = CGPointMake(CGRectGetMidX(bounds), CGRectGetMaxY(bounds)); |
65 } |
64 } |
66 CGContextDrawLinearGradient(context, gradient, start, end, 0); |
65 CGContextDrawLinearGradient(context, gradient, start, end, 0); |
67 CGColorSpaceRelease(rgb); |
66 CGColorSpaceRelease(rgb); |
68 CGGradientRelease(gradient); |
67 CGGradientRelease(gradient); |
69 |
68 |
70 // Draw borders. |
69 // Draw borders. |
71 float borderThickness = 1.0; |
70 float borderThickness = 1.0; |
72 [[UIColor colorWithWhite:0.7 alpha:1.0] set]; |
71 [[UIColor colorWithWhite:0.7f alpha:1.0] set]; |
73 CGRect borderRect = bounds; |
72 CGRect borderRect = bounds; |
74 if (splitViewController.vertical) { |
73 if (splitViewController.vertical) { |
75 borderRect.size.width = borderThickness; |
74 borderRect.size.width = borderThickness; |
76 UIRectFill(borderRect); |
75 UIRectFill(borderRect); |
77 borderRect.origin.x = CGRectGetMaxX(bounds) - borderThickness; |
76 borderRect.origin.x = CGRectGetMaxX(bounds) - borderThickness; |
78 UIRectFill(borderRect); |
77 UIRectFill(borderRect); |
79 |
78 |
80 } else { |
79 } else { |
81 borderRect.size.height = borderThickness; |
80 borderRect.size.height = borderThickness; |
82 UIRectFill(borderRect); |
81 UIRectFill(borderRect); |
83 borderRect.origin.y = CGRectGetMaxY(bounds) - borderThickness; |
82 borderRect.origin.y = CGRectGetMaxY(bounds) - borderThickness; |
84 UIRectFill(borderRect); |
83 UIRectFill(borderRect); |
85 } |
84 } |
86 |
85 |
87 // Draw grip. |
86 // Draw grip. |
88 [self drawGripThumbInRect:bounds]; |
87 [self drawGripThumbInRect:bounds]; |
89 } |
88 } |
90 } |
89 } |
91 |
90 |
92 |
91 |
93 - (void)drawGripThumbInRect:(CGRect)rect |
92 - (void)drawGripThumbInRect:(CGRect)rect |
94 { |
93 { |
95 float width = 9.0; |
94 float width = 9.0; |
96 float height; |
95 float height; |
97 if (splitViewController.vertical) { |
96 if (splitViewController.vertical) { |
98 height = 30.0; |
97 height = 30.0; |
99 } else { |
98 } else { |
100 height = width; |
99 height = width; |
101 width = 30.0; |
100 width = 30.0; |
102 } |
101 } |
103 |
102 |
104 // Draw grip in centred in rect. |
103 // Draw grip in centred in rect. |
105 CGRect gripRect = CGRectMake(0, 0, width, height); |
104 CGRect gripRect = CGRectMake(0, 0, width, height); |
106 gripRect.origin.x = ((rect.size.width - gripRect.size.width) / 2.0); |
105 gripRect.origin.x = ((rect.size.width - gripRect.size.width) / 2.f); |
107 gripRect.origin.y = ((rect.size.height - gripRect.size.height) / 2.0); |
106 gripRect.origin.y = ((rect.size.height - gripRect.size.height) / 2.f); |
108 |
107 |
109 float stripThickness = 1.0; |
108 float stripThickness = 1.0; |
110 UIColor *stripColor = [UIColor colorWithWhite:0.35 alpha:1.0]; |
109 UIColor *stripColor = [UIColor colorWithWhite:0.35f alpha:1.0]; |
111 UIColor *lightColor = [UIColor colorWithWhite:1.0 alpha:1.0]; |
110 UIColor *lightColor = [UIColor colorWithWhite:1.0 alpha:1.0]; |
112 float space = 3.0; |
111 float space = 3.0; |
113 if (splitViewController.vertical) { |
112 if (splitViewController.vertical) { |
114 gripRect.size.width = stripThickness; |
113 gripRect.size.width = stripThickness; |
115 [stripColor set]; |
114 [stripColor set]; |
116 UIRectFill(gripRect); |
115 UIRectFill(gripRect); |
117 |
116 |
118 gripRect.origin.x += stripThickness; |
117 gripRect.origin.x += stripThickness; |
119 gripRect.origin.y += 1; |
118 gripRect.origin.y += 1; |
120 [lightColor set]; |
119 [lightColor set]; |
121 UIRectFill(gripRect); |
120 UIRectFill(gripRect); |
122 gripRect.origin.x -= stripThickness; |
121 gripRect.origin.x -= stripThickness; |
123 gripRect.origin.y -= 1; |
122 gripRect.origin.y -= 1; |
124 |
123 |
125 gripRect.origin.x += space + stripThickness; |
124 gripRect.origin.x += space + stripThickness; |
126 [stripColor set]; |
125 [stripColor set]; |
127 UIRectFill(gripRect); |
126 UIRectFill(gripRect); |
128 |
127 |
129 gripRect.origin.x += stripThickness; |
128 gripRect.origin.x += stripThickness; |
130 gripRect.origin.y += 1; |
129 gripRect.origin.y += 1; |
131 [lightColor set]; |
130 [lightColor set]; |
132 UIRectFill(gripRect); |
131 UIRectFill(gripRect); |
133 gripRect.origin.x -= stripThickness; |
132 gripRect.origin.x -= stripThickness; |
134 gripRect.origin.y -= 1; |
133 gripRect.origin.y -= 1; |
135 |
134 |
136 gripRect.origin.x += space + stripThickness; |
135 gripRect.origin.x += space + stripThickness; |
137 [stripColor set]; |
136 [stripColor set]; |
138 UIRectFill(gripRect); |
137 UIRectFill(gripRect); |
139 |
138 |
140 gripRect.origin.x += stripThickness; |
139 gripRect.origin.x += stripThickness; |
141 gripRect.origin.y += 1; |
140 gripRect.origin.y += 1; |
142 [lightColor set]; |
141 [lightColor set]; |
143 UIRectFill(gripRect); |
142 UIRectFill(gripRect); |
144 |
143 |
145 } else { |
144 } else { |
146 gripRect.size.height = stripThickness; |
145 gripRect.size.height = stripThickness; |
147 [stripColor set]; |
146 [stripColor set]; |
148 UIRectFill(gripRect); |
147 UIRectFill(gripRect); |
149 |
148 |
150 gripRect.origin.y += stripThickness; |
149 gripRect.origin.y += stripThickness; |
151 gripRect.origin.x -= 1; |
150 gripRect.origin.x -= 1; |
152 [lightColor set]; |
151 [lightColor set]; |
153 UIRectFill(gripRect); |
152 UIRectFill(gripRect); |
154 gripRect.origin.y -= stripThickness; |
153 gripRect.origin.y -= stripThickness; |
155 gripRect.origin.x += 1; |
154 gripRect.origin.x += 1; |
156 |
155 |
157 gripRect.origin.y += space + stripThickness; |
156 gripRect.origin.y += space + stripThickness; |
158 [stripColor set]; |
157 [stripColor set]; |
159 UIRectFill(gripRect); |
158 UIRectFill(gripRect); |
160 |
159 |
161 gripRect.origin.y += stripThickness; |
160 gripRect.origin.y += stripThickness; |
162 gripRect.origin.x -= 1; |
161 gripRect.origin.x -= 1; |
163 [lightColor set]; |
162 [lightColor set]; |
164 UIRectFill(gripRect); |
163 UIRectFill(gripRect); |
165 gripRect.origin.y -= stripThickness; |
164 gripRect.origin.y -= stripThickness; |
166 gripRect.origin.x += 1; |
165 gripRect.origin.x += 1; |
167 |
166 |
168 gripRect.origin.y += space + stripThickness; |
167 gripRect.origin.y += space + stripThickness; |
169 [stripColor set]; |
168 [stripColor set]; |
170 UIRectFill(gripRect); |
169 UIRectFill(gripRect); |
171 |
170 |
172 gripRect.origin.y += stripThickness; |
171 gripRect.origin.y += stripThickness; |
173 gripRect.origin.x -= 1; |
172 gripRect.origin.x -= 1; |
174 [lightColor set]; |
173 [lightColor set]; |
175 UIRectFill(gripRect); |
174 UIRectFill(gripRect); |
176 } |
175 } |
177 } |
176 } |
178 |
177 |
179 |
178 |
180 #pragma mark - |
179 #pragma mark - |
181 #pragma mark Interaction |
180 #pragma mark Interaction |
182 |
181 |
183 |
182 |
184 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event |
183 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event |
185 { |
184 { |
186 UITouch *touch = [touches anyObject]; |
185 UITouch *touch = [touches anyObject]; |
187 if (touch) { |
186 if (touch) { |
188 CGPoint lastPt = [touch previousLocationInView:self]; |
187 CGPoint lastPt = [touch previousLocationInView:self]; |
189 CGPoint pt = [touch locationInView:self]; |
188 CGPoint pt = [touch locationInView:self]; |
190 float offset = (splitViewController.vertical) ? pt.x - lastPt.x : pt.y - lastPt.y; |
189 float offset = (splitViewController.vertical) ? pt.x - lastPt.x : pt.y - lastPt.y; |
191 if (!splitViewController.masterBeforeDetail) { |
190 if (!splitViewController.masterBeforeDetail) { |
192 offset = -offset; |
191 offset = -offset; |
193 } |
192 } |
194 splitViewController.splitPosition = splitViewController.splitPosition + offset; |
193 splitViewController.splitPosition = splitViewController.splitPosition + offset; |
195 } |
194 } |
196 } |
195 } |
197 |
196 |
198 |
197 |
199 #pragma mark - |
198 #pragma mark - |
200 #pragma mark Accessors and properties |
199 #pragma mark Accessors and properties |
201 |
200 |
202 |
201 |
203 - (void)setAllowsDragging:(BOOL)flag |
202 - (void)setAllowsDragging:(BOOL)flag |
204 { |
203 { |
205 if (flag != allowsDragging) { |
204 if (flag != allowsDragging) { |
206 allowsDragging = flag; |
205 allowsDragging = flag; |
207 self.userInteractionEnabled = allowsDragging; |
206 self.userInteractionEnabled = allowsDragging; |
208 } |
207 } |
209 } |
208 } |
210 |
209 |
211 |
210 |
212 @synthesize splitViewController; |
211 @synthesize splitViewController; |
213 @synthesize allowsDragging; |
212 @synthesize allowsDragging; |