在 webView 中渲染本地 PDF 会切断右侧

Posted

技术标签:

【中文标题】在 webView 中渲染本地 PDF 会切断右侧【英文标题】:Rendering Local PDF in webView cuts off the right side 【发布时间】:2016-05-27 07:20:43 【问题描述】:

我正在 webView 中呈现本地 PDF,但它切断了 PDF 的右侧。下面是代码 -

if let pdf = NSBundle.mainBundle().URLForResource("myPDF", withExtension: "pdf", subdirectory: nil, localization: nil)  
            let req = NSURLRequest(URL: pdf)

            let webView = UIWebView(frame: CGRectMake(0,60,self.view.frame.size.width,self.view.frame.size.height))
            webView.scalesPageToFit = true
            webView.loadRequest(req)
            self.view.addSubview(webView)
        

任何帮助将不胜感激。

谢谢!

【问题讨论】:

【参考方案1】:

试试这个,

  if let pdf = NSBundle.mainBundle().URLForResource("myPDF", withExtension: "pdf", subdirectory: nil, localization: nil)  
        let req = NSURLRequest(URL: pdf)

        let webView = UIWebView(frame: CGRectMake(0,60,self.view.frame.size.width,self.view.frame.size.height))

        self.view.addSubview(webView)

        webView.loadRequest(req)

    

希望这会有所帮助:)

【讨论】:

不,它仍然切断了 PDF 的右侧【参考方案2】:

我得到了解决方案 -

刚刚将代码从 viewDidLoad 移到 viewWillAppear,它解决了我的问题 :)。

【讨论】:

以上是关于在 webView 中渲染本地 PDF 会切断右侧的主要内容,如果未能解决你的问题,请参考以下文章