• ios -WKWebView 高度 准确,留有空白的解决方案


     

    #import "ViewController.h"

    #import <WebKit/WebKit.h> 

    @interface ViewController ()<WKNavigationDelegate>

    @property (nonatomic, strong)WKWebView *webView;

     

    @end

     

    @implementation ViewController

     

    - (void)viewDidLoad

    {

        _webView = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 1)];

        _webView.UIDelegate = self;

        _webView.navigationDelegate = self;

        [self.view addSubview:_webView];

        NSString *url = [NSString stringWithFormat:@"https://mdetail.tmall.com/templates/pages/desc?id=13128565333"];

        NSLog(@"dfurk:%@",url);

        [self.webView loadRequest:[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:url]]];

     

        [self.webView.scrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];

    }

     

    - (void)dealloc {

        

        [self.webView.scrollView removeObserver:self forKeyPath:@"contentSize" context:nil];

    }

     

    - (void)observeValueForKeyPath:(NSString *)keyPath

                          ofObject:(id)object

                            change:(NSDictionary *)change

                           context:(void *)context

    {

        if (object == self.webView.scrollView && [keyPath isEqual:@"contentSize"]) {

            // we are here because the contentSize of the WebView's scrollview changed.

            

            UIScrollView *scrollView = self.webView.scrollView;

            self.webView.frame = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);

            NSLog(@"New contentSize: %f x %f", scrollView.contentSize.width, scrollView.contentSize.height);

        }

    }

    /*

    #pragma mark - Navigation

     

    // In a storyboard-based application, you will often want to do a little preparation before navigation

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

        // Get the new view controller using [segue destinationViewController].

        // Pass the selected object to the new view controller.

    }

    */

     

    @end

  • 相关阅读:
    windows2019开发windows服务
    vue开发笔记
    kafka管理界面 kafka eagle
    WPF 无边框窗体改变大小和移动
    3种方法改变Linux的默认shell
    Linux,原来cd命令这样玩
    Linux中cp命令的使用方法
    Linux 中ls命令的使用
    如何查看Linux的内存使用率
    Linux中如何重命名文件
  • 原文地址:https://www.cnblogs.com/shenlaiyaoshi/p/8676622.html
Copyright © 2020-2023  润新知