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