我的目標是加載一個遠程html,替換標籤並在webview中顯示它。一切工作正常,但isUserInteractionEnabled = true它不工作。我知道這是因爲我不能向下滾動。我認爲這是關於在session.dataTask()內調用self.webView.loadHTMLString(html!,baseURL:nil)。我的問題是:有沒有更好的方法來實現這一目標?Swift3 webview isUserInteractionEnabled不能正常工作
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = "https://example.com"
let requestURL = URL(string:url)
var request = URLRequest(url: requestURL!)
request.httpMethod = "GET"
let session = URLSession.shared
self.webView.isUserInteractionEnabled = true
session.dataTask(with: request) { (data, response, err) in
let html = String(data: data!, encoding: String.Encoding.utf8) as String!
self.webView.loadHTMLString(html!, baseURL: nil)
}.resume()
// webView.loadRequest(request)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
您的代碼正在爲我工作。我可以向下滾動,但在任何鏈接點擊都不起作用。 –