解决iOS11webview顶部空白条的问题
在 iOS 11 使用 webview 发现顶部会有一个空白条,怎么也去不掉,通过设置 contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever 就可以解决了,具体的代码如下:
10年积累的成都做网站、成都网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有伊美免费网站建设让你可以放心的选择与我们合作。
// // 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)); } //加载失败时调用 - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { NSLog(@"%@",NSStringFromSelector(_cmd)); NSLog(@"error: %@",error); UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"信息" message:@"连接服务器失败,请检查网络" 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
本文标题:解决iOS11webview顶部空白条的问题
本文URL:http://cdiso.cn/article/gphcps.html