zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    mybatis基础学习3---特殊sql语句(备忘)
    5.dos网络配置命令,重新获取ip刷新dns
    Guarded Suspension设计模式
    多线程Future设计模式
    多线程不可变对象设计模式immutable
    多线程读写锁分离设计模式
    多个人过门引出线程安全问题
    库存管理系统项目总结
    简单认识C#
    数据类型,变量,与运算符
  • 原文地址:https://www.cnblogs.com/shenlaiyaoshi/p/8676622.html
Copyright © 2011-2022 走看看