简体   繁体   English

从UIWebView更改为WKWebView

[英]Change from UIWebView to WKWebView

I'm trying to change my UIWebView to WKWebView . 我正在尝试将UIWebView更改为WKWebView

My WebPageViewController just looks this simple on Storyboards: 我的WebPageViewController在Storyboard上看起来很简单: 在此处输入图片说明

I'd like to implement the Reading View and back buttons and estimated progress, but I'm not sure if I'm even getting this first step right. 我想实现“阅读视图”和“后退”按钮以及预计的进度,但是我不确定我是否正确地迈出了第一步。

If the first step is right though, and I'm wanting to set up the configuration, am I adding something like this to my code?: WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init]; 如果第一步正确,但是我想设置配置,是否要在代码中添加这样的内容?: WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];

And would I need to add a @property (strong, nonatomic) WKWebViewConfiguration *configuration; 我是否需要添加一个@property (strong, nonatomic) WKWebViewConfiguration *configuration; to get it all working? 使一切正常?

Here's my code changes so far if needed: 到目前为止,如果需要,这是我的代码更改:

WebPageViewController.m UIWebView WebPageViewController.m UIWebView

@property (strong, nonatomic) IBOutlet UIWebView *webView;

-(void)viewWillAppear:(BOOL)animated {
    NSURL *url = [NSURL URLWithString:stringWeb];

    [self.webView loadRequest:[NSURLRequest requestWithURL:url]];
}

WebViewController.m WKWebView WebViewController.m WKWebView

@property (strong, nonatomic) IBOutlet WKWebView *webView;

-(void)viewWillAppear:(BOOL)animated {
NSURL *url = [NSURL URLWithString:stringWeb];

[self.webView loadRequest:[NSURLRequest requestWithURL:url]];
}

You can instantiate and set the WKWebViewConfiguration on the web view in viewDidLoad without storing it in a property. 您可以在viewDidLoad的Web视图上实例化和设置WKWebViewConfiguration而不将其存储在属性中。

- (void)viewDidLoad {
  [super viewDidLoad];

  WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
  // ...
  self.webView.configuration = configuration;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM