1
1

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.

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

Posted at

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が取得できている

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

1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?