This repository has been archived by the owner on Mar 7, 2023. It is now read-only.
/
GuideIntroViewController.m
227 lines (188 loc) · 6.75 KB
/
GuideIntroViewController.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
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
220
221
222
223
224
225
226
227
//
// GuideIntroViewController.m
// iFixit
//
// Created by David Patierno on 8/9/10.
// Copyright 2010 iFixit. All rights reserved.
//
#import "GuideIntroViewController.h"
#import "GuideCatchingWebView.h"
#import "Guide.h"
#import "UIImageView+WebCache.h"
#import "Config.h"
#import "SVWebViewController.h"
#import <QuartzCore/QuartzCore.h>
@implementation GuideIntroViewController
@synthesize headerTextDozuki;
@synthesize delegate, headerImageIFixit, headerImageMake, swipeLabel, headerImageZeal;
@synthesize overlayView;
@synthesize guide=_guide;
@synthesize device, mainImage, webView, huge, html;
// Load the view nib and initialize the guide.
- (id)initWithGuide:(Guide *)guide {
if ((self = [super initWithNibName:@"GuideIntroView" bundle:nil])) {
self.guide = guide;
self.huge = nil;
}
return self;
}
- (void)removeWebViewShadows {
NSArray *subviews = [webView subviews];
if ([subviews count]) {
for (UIView *wview in [[subviews objectAtIndex:0] subviews]) {
if ([wview isKindOfClass:[UIImageView class]]) {
wview.hidden = YES;
}
}
}
}
- (void)addViewShadow:(UIView *)view {
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
// Apply a blur!
[view.layer setRasterizationScale:0.25];
[view.layer setShouldRasterize:YES];
return;
}
view.layer.masksToBounds = NO;
view.layer.shadowOffset = CGSizeMake(0.0, 1.0);
view.layer.shadowRadius = 3.0;
view.layer.shadowOpacity = 0.8;
view.layer.shadowPath = [UIBezierPath bezierPathWithRect:view.bounds].CGPath;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Set the appropriate header image.
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
if ([Config currentConfig].site == ConfigMake || [Config currentConfig].site == ConfigMakeDev) {
headerImageMake.hidden = NO;
} else if ([Config currentConfig].site == ConfigIFixit || [Config currentConfig].site == ConfigIFixitDev) {
headerImageIFixit.hidden = NO;
} else if ([Config currentConfig].site == ConfigZeal) {
headerImageZeal.hidden = NO;
} else {
headerTextDozuki.font = [UIFont fontWithName:@"Lobster" size:75.0];
headerTextDozuki.text = [[Config currentConfig].siteData valueForKey:@"title"];
headerTextDozuki.hidden = NO;
}
}
// Hide the swipe label if there are no steps.
if (![self.guide.steps count])
swipeLabel.hidden = YES;
UIColor *bgColor = [UIColor clearColor];
if ([[Config currentConfig].backgroundColor isEqual:[UIColor whiteColor]]) {
overlayView.backgroundColor = [UIColor whiteColor];
overlayView.alpha = 0.3;
}
self.view.backgroundColor = bgColor;
webView.modalDelegate = delegate;
webView.backgroundColor = bgColor;
webView.opaque = NO;
// Load the intro contents as HTML.
NSString *header = [NSString stringWithFormat:@"<html><head><style type=\"text/css\"> %@ </style></head><body class=\"%@\">",
[Config currentConfig].introCSS,
([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) ? @"big" : @"small"];
NSString *footer = @"</body></html>";
NSString *body = self.guide.introduction_rendered;
//NSString *body = guide.introduction;
self.html = [NSString stringWithFormat:@"%@%@%@", header, body, footer];
[webView loadHTMLString:html baseURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@", [Config host]]]];
[self removeWebViewShadows];
[device setText:self.guide.device];
// Add a shadow to the image
[self addViewShadow:mainImage];
[mainImage setImageWithURL:[self.guide.image URLForSize:@"standard"] placeholderImage:nil];
}
// Because the web view has a white background, it starts hidden.
// After the content is loaded, we wait a small amount of time before showing it to prevent flicker.
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[self performSelector:@selector(showWebView:) withObject:nil afterDelay:0.2];
}
- (void)showWebView:(id)sender {
webView.hidden = NO;
}
- (IBAction)zoomImage:(id)sender {
// Disabled on the intro.
return;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}
- (void)layoutLandscape {
// iPad
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
swipeLabel.frame = CGRectMake(600.0, 563.0, 375.0, 84.0);
webView.frame = CGRectMake(20.0, 160.0, 984.0, 395.0);
}
// iPhone
else {
CGRect frame = webView.frame;
frame.size.height = 180;
webView.frame = frame;
}
}
- (void)layoutPortrait {
// iPad
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
swipeLabel.frame = CGRectMake(340.0, 790.0, 375.0, 84.0);
webView.frame = CGRectMake(20.0, 160.0, 728.0, 605.0);
}
// iPhone
else {
CGRect frame = webView.frame;
frame.size.height = 305;
webView.frame = frame;
}
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
[self layoutLandscape];
}
else {
[self layoutPortrait];
}
// Re-flow HTML
[webView loadHTMLString:html baseURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@", [Config host]]]];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
self.headerImageIFixit = nil;
self.headerImageMake = nil;
self.swipeLabel = nil;
self.device = nil;
self.mainImage = nil;
self.webView = nil;
[self setOverlayView:nil];
[self setHeaderTextDozuki:nil];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[self setOverlayView:nil];
[self setHeaderTextDozuki:nil];
[super viewDidUnload];
self.headerImageIFixit = nil;
self.headerImageMake = nil;
self.swipeLabel = nil;
self.device = nil;
self.mainImage = nil;
self.webView = nil;
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
webView.delegate = nil;
[_guide release];
[huge release];
[html release];
[headerImageIFixit release];
[headerImageMake release];
[swipeLabel release];
[device release];
[mainImage release];
[webView release];
[overlayView release];
[headerTextDozuki release];
[super dealloc];
}
@end