Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

293
Visualizações
WKWebView inside Scroll View

How can I put a WKWebView inside a Scroll View consider that I must have others elements after Web View.

. View ... Scroll View ....... ImageView ....... WKWebView ....... Button

See the demo image

  • Issue 1: Disable scroll for WKWebView
  • Issue 2: Set full content height for WKWebView

Check my sample project

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

If you mean to get the content height of the html in WKWebView to make it non-scrollable inside UIScrollView, then read on.

You need to observe (via delegate) the content height of your webView. I'm giving you these steps, since you quite know what you're doing, and you're almost there.

Make an outlet out of your webView height constraint

@IBOutlet weak var constraint_WebViewHeight: NSLayoutConstraint!

Subscribe to webView's delegate

This will let you know (your controller when your webView has finished loading the contents of your site.

self.webView.navigationDelegate = self

Conform to protocol

Inside the didFinish navigation method of WKNavigationDelegate, you then adjust the constant of your webView height constraint. Put some animation if you want to :)

extension ViewController: WKNavigationDelegate {
    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
            self.constraint_WebViewHeight.constant = webView.scrollView.contentSize.height
        }
    }
}

Finally, fix your constraints.

a. Remove your imageView bottom constraint. b. Add bottom constraint to your save button to the scrollView.

This will make your scrollView scrollable.

Voila! This yields this result.

enter image description here

I hope this helps!

over 4 years ago · Santiago Trujillo Relatório

0

As per the understanding you want webview not to scroll well if the page is bigger than your screen it will scroll right? To show the full page. Although you can change the isscrollingenabled to false from interface builder or from code by using object of scrollview. To set full height give constraint 0,0,0,0 from all sides and it will surely stretch to whole screen

over 4 years ago · Santiago Trujillo Relatório

0

It's wrong approach. You should use WKWebView's scrollView.

You need reserve space for image and button with html margins using javascript

[NSString stringWithFormat:@"document.body.style.margin = '%dpx %dpx %dpx %dpx'", (int)margins.top, (int)margins.right, (int)margins.bottom, (int)margins.left]

or directly in html body if you able to access it.

Add imageview and button into WKWebView's scrollView.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda