実現したいこと
WKWebViewでgoogleを表示できれば良いです。
環境
- Xcode 10.1
- Swift 4.0
問題
以下のソースを記述し、iPhone Xのシミュレータで試していますが、WKWebViewが表示されません。
import UIKit import WebKit class WebViewController: UIViewController, WKNavigationDelegate { let webview = WKWebView() let testurl = URL(string: "https://www.google.co.jp") override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. webview.frame = view.bounds webview.navigationDelegate = self webview.translatesAutoresizingMaskIntoConstraints = false webview.backgroundColor = UIColor.green webview.autoresizingMask = [.flexibleWidth, .flexibleHeight] self.view.addSubview(webview) webview.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0.0).isActive = true webview.trailingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0.0).isActive = true webview.topAnchor.constraint(equalTo: view.topAnchor, constant: 0.0).isActive = true webview.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0.0).isActive = true let request = URLRequest(url: (testurl)!) self.webview.load(request) } }
どのようなviewが作成されているのかを確認するため、capture view hierarchyを実行したところ、以下のような結果が得られました。
どうもそもそもWKWebViewが追加できていないように見えます。
ご意見等頂けますと幸いです。
回答2件
あなたの回答
tips
プレビュー