做UIWebView时明白的一些问题

//获取设备的物理高度,宽度

#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];

    }

}

UIWebView回调一些方法,首先要继承他的委托方法,其实就是Android里的接口
还有IOS里面的当无网络或者数据获取不到时,加载错误界面是通过浮层实现的,点击重新加载时再把该view从父view里移除
//开始加载

- (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];

    

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值