-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathAPSplitViewController.m
More file actions
219 lines (166 loc) · 8.09 KB
/
APSplitViewController.m
File metadata and controls
219 lines (166 loc) · 8.09 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
//
// APBaseSplitViewController.m
// SplitSample
//
// Created by slatvick on 2/15/11.
// Copyright 2011 Alterplay. All rights reserved.
//
#import "APSplitViewController.h"
#define constDividerWidth 1.0f
#define constMasterWidth 320.0f
#define constDetailStartPoint (constMasterWidth+constDividerWidth)
static float koefficient = 0.0f; // Need to fix a bug with 20px near the statusbar
@interface APSplitViewController()
//- (void) layoutSubviews;
@end
@implementation APSplitViewController
@synthesize master = _master;
@synthesize detail = _detail;
#pragma mark -
#pragma mark Helpers
// returns size of split view
- (CGSize) sizeRotated {
UIScreen *screen = [UIScreen mainScreen];
CGRect bounds = screen.bounds; // always implicitly in Portrait orientation.
CGRect appFrame = screen.applicationFrame;
CGSize size = bounds.size;
float statusBarHeight = MAX((bounds.size.width - appFrame.size.width), (bounds.size.height - appFrame.size.height));
// let's figure out if width/height must be swapped
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
// we're going to landscape, which means we gotta swap them
size.width = bounds.size.height;
size.height = bounds.size.width;
}
size.height = size.height -statusBarHeight -self.tabBarController.tabBar.frame.size.height;
return size;
}
- (void) layoutSubviews {
NSLog(@"layoutSubviews");
CGSize size = [self sizeRotated];
_master.view.frame = CGRectMake(0,
0 - koefficient,
constMasterWidth,
size.height + koefficient);
_detail.view.frame = CGRectMake(constDetailStartPoint,
0 - koefficient,
size.width - constDetailStartPoint,
size.height + koefficient);
_divider.frame = CGRectMake(constMasterWidth, 0, constDividerWidth, size.height);
}
#pragma mark - View lifecycle
- (void) pushToMasterController:(UIViewController *)controller {
CGSize size = [self sizeRotated];
controller.view.frame = CGRectMake(0, 0, constMasterWidth, size.height);
controller.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth
| UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin
| UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin;
// controller.view.backgroundColor = [UIColor redColor];
[_master pushViewController:controller animated:NO];
_master.view.frame = CGRectMake(0, 0, constMasterWidth, size.height);
_master.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
_master.view.backgroundColor = [UIColor purpleColor];
[self.view addSubview:_master.view];
[self.view bringSubviewToFront:_divider];
}
- (void) pushToDetailController:(UIViewController *)controller {
CGSize size = [self sizeRotated];
controller.view.frame = CGRectMake(0, 0, size.width-constDetailStartPoint, size.height);
controller.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth
| UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin
| UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin;
// controller.view.backgroundColor = [UIColor lightGrayColor];
[_detail pushViewController:controller animated:NO];
_detail.view.frame = CGRectMake(constDetailStartPoint, 0, size.width-constDetailStartPoint, size.height);
_detail.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
// _detail.view.backgroundColor = [UIColor darkGrayColor];
[self.view addSubview:_detail.view];
[self.view bringSubviewToFront:_divider];
}
- (void) loadView {
CGSize size = [self sizeRotated];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.view = view;
self.view.backgroundColor = [UIColor grayColor];
// slatvick: old divider
_divider = [[UIView alloc] init];
_divider.frame = CGRectMake(constMasterWidth, 0, constDividerWidth, size.height);
_divider.backgroundColor = [UIColor redColor];
_divider.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin;
[self.view addSubview:_divider];
UIImage *image = [UIImage imageNamed:@"split-divider.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(-4, 0, image.size.width, image.size.height);
[_divider addSubview:imageView];
}
- (void) viewDidLoad {
[super viewDidLoad];
_master = [[APNavigationControllerForSplitController alloc] initWithSplit:self];
_detail = [[APNavigationControllerForSplitController alloc] initWithSplit:self];
// don't remember what for?
//[_master viewDidLoad];
//[_detail viewDidLoad];
NSLog(@"viewDidLoad complete");
// NSLog(@" self.view.frame: %@", NSStringFromCGRect(self.view.frame));
// NSLog(@"_master.view.frame: %@", NSStringFromCGRect(_master.view.frame));
// NSLog(@"_detail.view.frame: %@", NSStringFromCGRect(_detail.view.frame));
}
#pragma mark -
#pragma mark STANDARD METHODS
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[_master viewWillAppear:animated];
[_detail viewWillAppear:animated];
}
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[_master viewDidAppear:animated];
[_detail viewDidAppear:animated];
// it's Needed to fix a bug with 20px near the statusbar
if (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
koefficient = 20.0f;
else
koefficient = 0.0f;
// [self layoutSubviews];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[_master viewWillDisappear:animated];
[_detail viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[_master viewDidDisappear:animated];
[_detail viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[_master willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
[_detail willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
// [self layoutSubviews];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[_master didRotateFromInterfaceOrientation:fromInterfaceOrientation];
[_detail didRotateFromInterfaceOrientation:fromInterfaceOrientation];
// [self layoutSubviews];
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[_master willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
[_detail willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[_master willAnimateFirstHalfOfRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
[_detail willAnimateFirstHalfOfRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
- (void)didAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
[_master didAnimateFirstHalfOfRotationToInterfaceOrientation:toInterfaceOrientation];
[_detail didAnimateFirstHalfOfRotationToInterfaceOrientation:toInterfaceOrientation];
}
- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration {
[_master willAnimateSecondHalfOfRotationFromInterfaceOrientation:fromInterfaceOrientation duration:duration];
[_detail willAnimateSecondHalfOfRotationFromInterfaceOrientation:fromInterfaceOrientation duration:duration];
}
@end