1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ContainerViewにWKWebViewを表示

Posted at

初学者のメモです。間違いや凡ミスなどありましたら、ごめんなさい。

コードで作っていきます。StoryBoardは使いません。

概要のみ

WKWebvViewを生成

webView = WKWebView()
webView.frame = self.view.frame
省略
self.view.addSubView(webView)

別ViewControllerでContainerViewを生成。

let containerView = UIView()
containerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(containerView)
NSLayoutConstraint.activate([containerView.leadinfAnchor.constraint( ~//constraint省略

//WKWebViewを定義したViewControllerを生成
let webView = ViewController()
addChildViewController(webView)
//この後willMove(toParent:)は自動的に呼び出されるので必須ではない。

webView.view.translatesAutoresizingMaskIntoConstraints = false
containerView.addSubview(webView.view)
NSLayoutConstraint.activate( ~//constraint省略

webView.didMove(toParentViewController: self)//カスタムのContainerViewを実装する場合、
//遷移がある場合はその完了後、ない場合はaddChild(_:)の後に、このメソッドを明示的に呼び出さなければならない。

また追記していきます。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?