【发布时间】:2014-11-19 03:39:17
【问题描述】:
我在 UIWebView 的滚动视图中添加了相同的子视图。当 webview 获取 contentSize 时,滚动视图将滚动到顶部。现在我知道事件在完成之前发生(某些图像可能仍在加载)但在获取文本内容之后。我应该怎么做怎么办?
这是代码,要查看您需要减慢请求的错误(使用边缘)!在加载完成之前滚动视图,然后等待。当请求完成时,您将看到视图滚动到顶部。
class WebViewController: UIViewController {
var mw = UIScreen.mainScreen().bounds.width
var mh = UIScreen.mainScreen().bounds.height
override func viewDidLoad() {
super.viewDidLoad()
var web = UIWebView(frame: CGRect(x: 0, y: 0, width: mw, height: mh))
var scrollview = web.scrollView
var tmp = UIView(frame: CGRect(x: 0, y: 0, width: mw, height: 300))
tmp.backgroundColor = UIColor.redColor()
scrollview.addSubview(tmp)
(scrollview.subviews.first as UIView).frame.origin.y = 300
let requestURL = NSURL(string: "http://stackoverflow.com/questions/27008545/how-to-disabled-uiwebview-auto-scroll-to-top-when-finished-load")
let request = NSURLRequest(URL: requestURL!)
web.loadRequest(request)
self.view.addSubview(web)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
【问题讨论】:
标签: ios swift uiwebview webviewdidfinishload