1

I added same subviews in the UIWebView's scrollview.When the webview get contentSize the scrollview will scroll to top.Now I'know the event happend before finished(some images may still loading) but after get the text content.What should i do?

This is the code,and to see the bug you need slow down the request(use edge)!! Before load finished scroll the view,then wait.When the request finished you will see the view scroll to top .

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.
}

}

six
  • 115
  • 1
  • 1
  • 7

1 Answers1

0

first you need to set the setContentSize: to the actual content size, not the frame size. That is if your content is e.g. 800px high, you should setContentSize:CGSizeMake(width, 800). using this you can set a UIScrollView that it should scroll to show 800px high content. If you set a UIScrollView's content size equal to its frame, no scrolling is performed and no scroll indicators appear .

Sport
  • 8,570
  • 6
  • 46
  • 65