UIWebView不滚动

Dan*_*nna 4 uiwebview uiviewcontroller swift

我的webview应用程序不向下滚动.我试过这段代码:

webview.scrollView.scrollEnabled = true
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

我必须将我的webview应用程序放入scrollview应用程序或webview应用程序就足够了吗?我已经尝试过,但直到现在才行.

我在ViewController.swift中的整个代码是:

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.
    }
}
Run Code Online (Sandbox Code Playgroud)

Dha*_*esh 6

只需在代码中添加以下行:

webView.userInteractionEnabled = true
Run Code Online (Sandbox Code Playgroud)

它会工作正常.


Alo*_*lok 6

要滚动webview视图,您应该检查给出三个步骤:

1)webview视图应该是: webView.userInteractionEnabled = true

2)webview视图应该是: webview.scrollView.scrollEnabled = true

3)webview视图内容应该超过你的webview框架.