Help us understand the problem. What is going on with this article?

WKWebViewを使ってロード後に表示したコンテンツサイズが取得できない

More than 1 year has passed since last update.

WKWebViewを使ってロード後に表示したWebコンテンツのサイズ取得したいだけなのに読み込み終わっても取得できなく困った末に苦肉の策で解決?した時の備忘録

Swift
open func load(_ request: URLRequest) -> WKNavigation?

URLを指定してWebをロードを行い、

Swift
optional public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!)

このdelegateでwebView.scrollView.contentSizeを見ると取得できていない・・・

open func viewDidAppear(_ animated: Bool)open func viewDidLayoutSubviews()
でも取得できるか試したが取得できない・・・

仕方なく
WKWebViewのメンバーのUIScrollViewをgetしUIScrollViewDelegateを設定して
optional public func scrollViewDidScroll(_ scrollView: UIScrollView)を受けるように追加
※ここではscrollView.contentSizeが取得できている

ただし、何度も呼ばれるメソッドなので、ここで何かの処理をするのには不向き。
何か他に方法を考えたいところ。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away