-
Notifications
You must be signed in to change notification settings - Fork 2
/
BaseWebViewController.m
174 lines (132 loc) · 5.05 KB
/
BaseWebViewController.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
//
// BaseWebViewController.m
// SoftCard803
//
// Created by apple on 15/3/12.
// Copyright (c) 2015年 iOSlearning. All rights reserved.
//
#import "BaseWebViewController.h"
#import "Common.h"
@interface BaseWebViewController ()
@end
@implementation BaseWebViewController
-(id)init{
self = [super init];
if(self){
webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 44)];
[webView setScalesPageToFit:YES];
[self.webView setDelegate:self];
[self.view addSubview:webView];
}
return self;
}
@synthesize webView,goBackButton,goFowardButton,cancelButton;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
CGFloat originX;
CGFloat originY;
CGFloat width;
CGFloat height;
if(IS_IPHONE_6_SCREEN){
originX = 0;
originY = 623;
width = 375;
height = 44;
}else{
originX = 0;
originY = 436;
width = 320;
height = 44;
}
UIView *bottomView = [[UIView alloc]initWithFrame:CGRectMake(originX, originY, width, height)];
[bottomView setBackgroundColor:[UIColor colorWithRed:248/255.0 green:248/255.0 blue:248/255.0 alpha:1.0]];
[bottomView.layer setShadowOffset:CGSizeMake(10, 10)];
[self.view addSubview:bottomView];
if(IS_IPHONE_6_SCREEN){
originX = 146.5;
originY = 623;
width = 44;
height = 44;
}else{
originX = 146.5;
originY = 436;
width = 44;
height = 44;
}
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(originX,originY,width,height)];
UIImage *image = [[UIImage alloc]init];
image = [UIImage imageNamed:@"goBackDisabled.png"];
[button setBackgroundImage:image forState:UIControlStateDisabled];
image = [UIImage imageNamed:@"goBackEnabled.png"];
[button setBackgroundImage:image forState:UIControlStateNormal];
[button addTarget:self action:@selector(goBackAction:) forControlEvents:UIControlEventTouchUpInside];
goBackButton = button;
[goBackButton setEnabled:NO];
[self.view addSubview:goBackButton];
originX = 209;
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(originX,originY, width, height)];
image = [UIImage imageNamed:@"goForwardDisabled"];
[button setBackgroundImage:image forState:UIControlStateDisabled];
image = [UIImage imageNamed:@"goForwardEnabled.png"];
[button setBackgroundImage:image forState:UIControlStateNormal];
[button setEnabled:NO];
[button addTarget:self action:@selector(goFowardAction:) forControlEvents:UIControlEventTouchUpInside];
goFowardButton = button;
[self.view addSubview:goFowardButton];
button = [UIButton buttonWithType:UIButtonTypeCustom];
originX = 276;
[button setFrame:CGRectMake(originX, originY, width, height)];
image = [UIImage imageNamed:@"cancelEnabled.png"];
[button setBackgroundImage:image forState:UIControlStateNormal];
[button addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
[button setEnabled:YES];
cancelButton = button;
[self.view addSubview:cancelButton];
originX = 0;
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[indicator setFrame:CGRectMake(originX, originY, width, height)];
[self.view addSubview:indicator];
[indicator setHidden:YES];
self.indicator = indicator;
}
-(void)goBackAction:(id)sender{
if(webView.canGoBack){
[webView goBack];
}
}
-(void)goFowardAction:(id)sender{
if(webView.canGoForward){
[webView goForward];
}
}
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
return YES;
}
-(void)webViewDidStartLoad:(UIWebView *)webView{
//[[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:YES];
self.indicator.hidden = NO;
}
-(void)webViewDidFinishLoad:(UIWebView *)web{
[[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];
[goBackButton setEnabled:web.canGoBack];
[goFowardButton setEnabled:web.canGoForward];
[self.indicator setHidden:YES];
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"];
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitDiskImageCacheEnabled"];
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitOfflineWebApplicationCacheEnabled"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
-(void)cancel:(id)sender{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(BOOL)prefersStatusBarHidden{
return YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end