//获取设备的物理高度,宽度
#define ScreenHeight [[UIScreen mainScreen]bounds].size.height
#define ScreenWidth [[UIScreen mainScreen]bounds].size.width
#define BottomNavHeight 49
#define isOversion_7_0 ([[UIDevice currentDevice].systemVersion floatValue]>=7.0 ? YES : NO)
@interface ViewController ()
@end
@implementation ViewController
自适应我直接设置了大小为屏幕的宽度,高度
- (void)viewDidLoad {
NSLog(@"viewDidLoad不是第一次启动");
[superviewDidLoad];
//初始化webView
webview = [[UIWebViewalloc ]initWithFrame:CGRectMake(0.0f,20.0f, ScreenWidth, ScreenHeight)];
[webviewsetScalesPageToFit:NO];
[webviewsetBackgroundColor:[UIColorclearColor]];
[webviewsetDelegate:self];
NSURLRequest * request = [NSURLRequestrequestWithURL:[NSURL URLWithString : @"http://th5.51qed.com/"]];
[self.viewaddSubview:webview];
[webviewloadRequest:request];
[webviewrelease];
//清除缓存
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStoragesharedHTTPCookieStorage];
for (cookie in [storagecookies]) {
[storagedeleteCookie:cookie];
}
//
//检查版本更新
if([[NSUserDefaultsstandardUserDefaults]boolForKey:@"firstLaunch"]){
// [self onCheckVersion];
}
}
- (void) webViewDidStartLoad:(UIWebView *)webView
{
//创建UIActivityIndicatorView背底半透明View
UIView *view = [[UIViewalloc] initWithFrame:CGRectMake(0,0, ScreenWidth,ScreenHeight)];
[viewsetTag:108];
[view setBackgroundColor:[UIColorwhiteColor]];
[viewsetAlpha:0.5];
[self.viewaddSubview:view];
activityIndicator = [[UIActivityIndicatorViewalloc] initWithFrame:CGRectMake(0.0f,0.0f, 32.0f, 32.0f)];
[activityIndicatorsetCenter:view.center];
[activityIndicatorsetBackgroundColor:[UIColorblackColor]];
[activityIndicatorsetActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
[view addSubview:activityIndicator];
[activityIndicatorstartAnimating];
NSLog(@"webViewDidStartLoad");
}
//加载结束
- (void) webViewDidFinishLoad:(UIWebView *)webView
{
[activityIndicatorstopAnimating];
UIView *view = (UIView*)[self.viewviewWithTag:108];
[view removeFromSuperview];
NSLog(@"webViewDidFinishLoad");
}
//加载数据失败
- (void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{ NSLog(@"didFailLoadWithError");
[activityIndicatorstopAnimating];
UIView *view = (UIView*)[self.viewviewWithTag:108];
[view removeFromSuperview];
commonview = [[CommonViewControlleralloc] init];
[selfpresentViewController:commonviewanimated:YEScompletion:nil];
}