在 iOS 11 使用 webview 發(fā)現(xiàn)頂部會(huì)有一個(gè)空白條,怎么也去不掉,通過(guò)設(shè)置 contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever 就可以解決了,具體的代碼如下:

創(chuàng)新互聯(lián)是一家專(zhuān)注網(wǎng)站建設(shè)、網(wǎng)絡(luò)營(yíng)銷(xiāo)策劃、
重慶小程序開(kāi)發(fā)、電子商務(wù)建設(shè)、網(wǎng)絡(luò)推廣、移動(dòng)互聯(lián)開(kāi)發(fā)、研究、服務(wù)為一體的技術(shù)型公司。公司成立10多年以來(lái),已經(jīng)為近1000家
成都宴會(huì)酒店設(shè)計(jì)各業(yè)的企業(yè)公司提供互聯(lián)網(wǎng)服務(wù)?,F(xiàn)在,服務(wù)的近1000家客戶與我們一路同行,見(jiàn)證我們的成長(zhǎng);未來(lái),我們一起分享成功的喜悅。//
// ViewController.m
// webView
//
// Created by exchen on 18/7/14.
// Copyright ? 2018年 exchen. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property(nonatomic, strong) UIWebView* webView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CGRect screen = [[UIScreen mainScreen] bounds];
//添加 UIWebView
self.webView = [[UIWebView alloc] initWithFrame: CGRectMake(0, 0, screen.size.width, screen.size.height)];
[self.view addSubview: self.webView];
NSURL * url = [NSURL URLWithString: @"https://www.exchen.net"];
NSURLRequest * request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
self.webView.delegate = self;
//解決 iOS 11 屏幕頂部顯示不全
if ([[UIDevice currentDevice].systemVersion floatValue] >= 11.0) {
self.webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
NSLog(@"%@",NSStringFromSelector(_cmd));
}
//加載失敗時(shí)調(diào)用
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
NSLog(@"%@",NSStringFromSelector(_cmd));
NSLog(@"error: %@",error);
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"信息" message:@"連接服務(wù)器失敗,請(qǐng)檢查網(wǎng)絡(luò)" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
exit(0);
}];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
return true;
}
@end原文地址:https://www.exchen.net/%E8%A7%A3%E5%86%B3-ios-11-webview-%E9%A1%B6%E9%83%A8%E7%A9%BA%E7%99%BD%E6%9D%A1%E7%9A%84%E9%97%AE%E9%A2%98.html
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
新聞標(biāo)題:解決iOS11webview頂部空白條的問(wèn)題-創(chuàng)新互聯(lián)
分享地址:http://fisionsoft.com.cn/article/espeg.html