• 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

  • 相关阅读:
    Eclipse 3.6 中安装WindowBuilder Pro及使用SWT Designer
    BEC听力训练 方法
    在Eclipse安装Aptana插件
    failed to create JVM 解决办法
    BEC听力训练 方法2
    ATF/Installing
    Eclipse中如何配置SWT
    语音信号 :lms算法麦克风语音降噪
    图像信号 matlab滤波器设计1 :高通滤波器应用和设计
    matlab m文件
  • 原文地址:https://www.cnblogs.com/shenlaiyaoshi/p/8676622.html
Copyright © 2020-2023  润新知