美文网首页图形控件
xib中如何使用WKWebView

xib中如何使用WKWebView

作者: 天天星期天 | 来源:发表于2017-02-27 17:07 被阅读1031次

    WKWebView推出有一段时间。公司近来要求所有的uiwebview升级到wkwebview。结果公司的很多界面用的都是xib。所以替换类型发现各种奔溃。废话不多说,直接上解决方法:
    1.xib中拉入UIView.(为什么拉入view呢?因为WKWebView的父类是uiview,而xib不能直接拉入WKWebView) ;


    2.自定义一个类myWK,继承自wkwebview。(因为wkwebview本身没有实现initWithCoder:方法。这个方法必须实现,否则xib会奔溃)。

    实现父类方法

    - (instancetype)initWithCoder:(NSCoder *)coder
    {
        CGRect frame = [[UIScreen mainScreen] bounds];
        WKWebViewConfiguration *myConfiguration = [WKWebViewConfiguration new];
        self = [super initWithFrame:frame configuration:myConfiguration];
    
        self.translatesAutoresizingMaskIntoConstraints = NO;
        
        return self;
    }
    

    3.替换第一步中xib拉入uiview的class,改为第二步中自定义的类。

    Paste_Image.png

    4.可以拉线自己调用了。

    Paste_Image.png

    相关文章

      网友评论

        本文标题:xib中如何使用WKWebView

        本文链接:https://www.haomeiwen.com/subject/lbnzwttx.html