我在 Xcode 的 IB 中沒找見WKWebView控件,只有 UIWebView 控件。
我新建了一個 UIView ,并將其自定義類設(shè)置為WKWebView,結(jié)果允許時,直接閃退了。
原因是因為WKWebView并沒有實現(xiàn)這個方法
- (instancetype)initWithCoder:(NSCoder *)coder NS_UNAVAILABLE;
經(jīng)過檢查,發(fā)現(xiàn)目前只能使用代碼方式來創(chuàng)建WKWebView。
后來想到一個方法 就是寫一個類繼承自WKWebView。在.m文件中重寫initWithCoder方法。
- (instancetype)initWithCoder:(NSCoder *)coder{
CGRect frame = [[UIScreen mainScreen] bounds];
WKWebViewConfiguration *myConfiguration = [WKWebViewConfiguration new];
self = [super initWithFrame:frame configuration:myConfiguration];
self.translatesAutoresizingMaskIntoConstraints = NO;
return self;
}
然后在xib中使用UIView,并將其自定義類設(shè)置為myWK即可使用。