IOS中UIWebView加載Loading的實(shí)現(xiàn)方法
第一種方法:使用UIView and UIActivityIndicatorView
//創(chuàng)建UIWebView
WebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, 320, 400)];
[WebView setUserInteractionEnabled:NO];
[WebView setBackgroundColor:[UIColor clearColor]];
[WebView setDelegate:self];
[WebView setOpaque:NO];//使網(wǎng)頁透明
NSString *path = @" NSURL *url = [NSURL URLWithString:path];
[WebView loadRequest:[NSURLRequest requestWithURL:url]];
//創(chuàng)建UIActivityIndicatorView背底半透明View
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[view setTag:103];
[view setBackgroundColor:[UIColor blackColor]];
[view setAlpha:0.8];
[self.view addSubview:view];
activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
[activityIndicator setCenter:view.center];
[activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
[view addSubview:activityIndicator];
[self.view addSubview:WebView];
[view release];
[WebView release];
//開始加載數(shù)據(jù)
- (void)webViewDidStartLoad:(UIWebView *)webView {
[activityIndicator startAnimating];
}
//數(shù)據(jù)加載完
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[activityIndicator stopAnimating];
UIView *view = (UIView *)[self.view viewWithTag:103];
[view removeFromSuperview];
}
第二種方法:使用UIAlertView and UIActivityIndicatorView
//加載網(wǎng)頁動(dòng)畫
- (void)webViewDidStartLoad:(UIWebView *)webView{
if (myAlert==nil){
myAlert = [[UIAlertView alloc] initWithTitle:nil
message: @"讀取中..."
delegate: self
cancelButtonTitle: nil
otherButtonTitles: nil];
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityView.frame = CGRectMake(120.f, 48.0f, 38.0f, 38.0f);
[myAlert addSubview:activityView];
[activityView startAnimating];
[myAlert show];
}
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
[myAlert dismissWithClickedButtonIndex:0 animated:YES];
}
方法三:使用UIWebView來加載gif圖片,除非你要用到webView,不然就不要使用這種方式來實(shí)現(xiàn)
NSData *gif = [NSData dataWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"1" ofType:@"gif"]];
// view生成
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(100, 100, 70, 30)];
webView.userInteractionEnabled = NO;//用戶不可交互
[webView loadData:gif MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];
[self.view addSubview:webView];
以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。
相關(guān)文章
iOS中使用schema協(xié)議調(diào)用APP和使用iframe打開APP的例子
這篇文章主要介紹了iOS中使用schema協(xié)議調(diào)用APP和使用iframe打開APP的例子,用在瀏覽器中打開APP,需要的朋友可以參考下2014-08-08
iOS利用CoreImage實(shí)現(xiàn)人臉識(shí)別詳解
OS的人臉識(shí)別從iOS 5(2011)就有了,不過一直沒怎么被關(guān)注過。人臉識(shí)別API允許開發(fā)者不僅可以檢測人臉,也可以檢測到面部的一些特殊屬性,比如說微笑或眨眼。下面這篇文章主要給大家介紹了iOS利用CoreImage實(shí)現(xiàn)人臉識(shí)別的相關(guān)資料,需要的朋友可以參考下。2017-05-05
iOS開發(fā)Quick Actions創(chuàng)建桌面Icon快捷方式
在本文里我們給大家分享了關(guān)于iOS開發(fā)Quick Actions創(chuàng)建桌面Icon快捷方式的相關(guān)知識(shí)點(diǎn)內(nèi)容,需要的讀者們可以參考下。2019-05-05
iOS開發(fā)中使用Picker View實(shí)現(xiàn)一個(gè)點(diǎn)菜應(yīng)用的UI示例
這篇文章主要介紹了iOS開發(fā)中使用Picker View實(shí)現(xiàn)一個(gè)點(diǎn)菜應(yīng)用的UI示例,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下2016-01-01
IOS實(shí)現(xiàn)基于CMPedometer的計(jì)步器
這篇文章主要為大家詳細(xì)介紹了IOS實(shí)現(xiàn)基于CMPedometer的計(jì)步器,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06
iOS如何優(yōu)雅地實(shí)現(xiàn)序列動(dòng)畫詳解
這篇文章主要給大家介紹了關(guān)于iOS如何優(yōu)雅地實(shí)現(xiàn)序列動(dòng)畫的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-12-12

