swiftuiviewcontrolleruiwebview

UIWebView doesn't scroll


My webview app doesn't scroll down. I tried with this code:

webview.scrollView.scrollEnabled = true

but it doesn't work.

Must I to put my webview app into a scrollview app or the webview app is enough? I already tried it but it doesn't work until now.

My whole code in ViewController.swift is:

import UIKit

class ViewController: UIViewController {

    @IBOutlet var webView: UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()

        //creo una costante di tipo NSURL
        let url = NSURL(string: "http://www.apple.com")

        //creo una richiesta di accesso a quello specifico indirizzo
        let request = NSURLRequest(URL: url!)

        //abilito lo zoom nella webView
        webView.scalesPageToFit = true
        webView.scrollView.scrollEnabled = true

        //carico la richiesta a quell'URL e aggiorna la WebView
        webView.loadRequest(request)

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

Solution

  • Just add this line in your code:

    webView.isUserInteractionEnabled = true
    

    And it will work fine.