简体   繁体   English

iOS 8 Swift UIWebView内容大小

[英]iOS 8 Swift UIWebView content size

I have an UIPageViewController with UIWebViews rendering .pdf as content. 我有一个UIPageViewController其中UIWebViews呈现.pdf为内容。 The UIWebView (content) is scaled to fit the frame width. 缩放UIWebView (内容)以适合框架宽度。 Some PDFs have double width so I tried to increase the frame width of the WebView 有些PDF的宽度是原来的两倍,所以我尝试增加WebView的框架宽度

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    var frame = self.mPageWebview.frame;
    frame.origin.x = 0;
    frame.origin.y = 0;

    if(frame.size.width > self.view.frame.size.width) {
        frame.size.width = self.view.frame.size.width * 2
        frame.size.height = self.view.frame.size.height
    }

    self.mPageWebview.frame = frame
}

For the rendering it works as intended (the frame just shows the left half of the PDF) but scrolling to the right does not work. 对于渲染,它可以按预期工作(框架仅显示PDF的左半部分),但向右滚动不起作用。 Can anyone help me with this? 谁能帮我这个?

For a scrollview to scroll, the contentview must be larger than the size of the scrollview. 为了使滚动视图滚动,contentview必须大于滚动视图的大小。 So, when you say you scaled the contentview's width to be equal to the frame's width, it won't scroll horizontally as the widths are the same. 因此,当您说将contentview的宽度缩放为等于框架的宽度时,由于宽度相同,它不会水平滚动。

Wait until the content has loaded then check its size and fit view to it, as long as the content is bigger than the view it will scroll. 等待直到内容加载完毕,然后检查其大小和适合的视图,只要内容大于它将滚动的视图。

func webViewDidFinishLoad(webView: UIWebView) {

    // Set webView frame to content size. 
    self.webViewHeightConstraint.constant = webView.scrollView.contentSize.height

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM