菜鸟教程小白 发表于 2022-12-12 16:13:45

IOS UIWebView 没有加载完整的网站


                                            <p><p>我正在学习 iOS。我正在尝试在 UIWebView 中加载网站。网页正在加载,但 WebView 未加载整个网站。相反, WebView 会加载网站的部分页面。这是代码
我做错了什么??</p>

<pre><code>import UIKit

class ViewController: UIViewController {

@IBOutlet weak var webView: UIWebView!

override func viewDidLoad() {
    super.viewDidLoad()


    // Do any additional setup after loading the view, typically from a nib.
}

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    webView.frame = self.view.frame
    let url = &#34;http://www.tradiestart.com.au&#34;
    let requestUrl = NSURL(string: url)
    let request = NSURLRequest(URL: requestUrl!)
    webView.loadRequest(request)
    webView.scrollView.scrollEnabled = true
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p><em>选择-1</em></p>

<pre><code> webView.scalesPageToFit = true
</code></pre>

<blockquote>
<p>if it is not work try choice no -2</p>
</blockquote>

<p><em>选择-2</em></p>

<pre><code> webView.frame = UIScreen.mainScreen().bounds
webView.center = self.view.center
webView.scalesPageToFit = true
</code></pre>

<p><em>选择-3</em></p>

<pre><code> webView.frame =CGRectMake(0,0, self.view.frame.size.width , self.view.frame.size.height)

or

    webView.frame =CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height)
</code></pre>

<p>附加 <a href="http://www.raywenderlich.com/forums/viewtopic.php?f=2&amp;t=5885" rel="noreferrer noopener nofollow">reference1</a> , <a href="https://developer.apple.com/library/ios/samplecode/UICatalog/Listings/Swift_UICatalog_WebViewController_swift.html" rel="noreferrer noopener nofollow">reference2</a> </p>

<p>这里我附上了 <a href="https://www.sendspace.com/file/snt7cv" rel="noreferrer noopener nofollow">sample project</a> </p>

<p>项目输出</p>

<p> <a href="/image/12GNR.png" rel="noreferrer noopener nofollow"><img src="/image/12GNR.png" alt="enter image description here"/></a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于IOS UIWebView 没有加载完整的网站,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/32390336/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/32390336/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: IOS UIWebView 没有加载完整的网站