有時候我們webView加載的網(wǎng)頁有自己的導航欄胶背,這樣就和系統(tǒng)的導航欄重復了如下圖:
二個導航欄
有二種方法解決:
1.隱藏系統(tǒng)的導航欄势腮,和就是做交互來實現(xiàn)網(wǎng)頁里返回事件(不推薦)买乃。
2.隱藏網(wǎng)頁導航(推薦)锈死。
其實我們只要我們在webView的加載結(jié)束代理里隱藏掉html里的header標簽就可以隱藏網(wǎng)頁的導航欄珍剑。
代碼如下:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
// 1.獲取頁面標題
NSString *string =@"document.title";
//獲取當前頁面的title 設置導航欄標題
NSString * title = [webViewstringByEvaluatingJavaScriptFromString:@"document.title"];
self.title = title;
[webView stringByEvaluatingJavaScriptFromString:string];
// 2.去掉頁面標題
NSMutableString *str = [NSMutableStringstring];
// 3.根據(jù)標簽類型獲取指定標簽的元素
[str appendString:@"var header = document.getElementsByTagName(\"header\")[0];”];
//移除頭部的導航欄
[str appendString:@"header.parentNode.removeChild(header);"];
[webView stringByEvaluatingJavaScriptFromString:str];
[selfperformSelector:@selector(hidenaction)withObject:selfafterDelay:0.1];
}
- (void)hidenaction{
//開始加載時隱藏webview 加載完后顯示掸宛,原因是 因為我們要去掉頭標簽,招拙,去掉的方法是在網(wǎng)頁加載完畢進行的唧瘾,,添加一個延時現(xiàn)實的方法 可以隱藏掉網(wǎng)頁先顯示頭標簽又被移除的過程别凤。使其看起來更自然一些
self.webView.hidden =NO;
}