簡體   English   中英

IOS UIWebView 未加載完整網站

[英]IOS UIWebView is not loading the full website

我正在學習iOS。 我正在嘗試在 UIWebView 中加載一個網站。 網頁正在加載,但網絡視圖未加載完整的網站。 相反,網絡視圖加載網站的部分頁面。 這是我做錯了什么的代碼?

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 = "http://www.tradiestart.com.au"
    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.
}
}

選擇-1

 webView.scalesPageToFit = true

如果它不起作用,請嘗試選擇 no -2

選擇-2

 webView.frame = UIScreen.mainScreen().bounds
 webView.center = self.view.center
 webView.scalesPageToFit = true

選擇-3

 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)

附加參考 1 , 參考 2

在這里我附上了示例項目

項目輸出

在此處輸入圖片說明

沒有什么是錯的。 代碼沒有任何問題。 我不知道你為什么拆分屏幕截圖,但該網站有一個移動版本,這就是你所看到的。 他們故意讓它看起來像那樣。 他們將其縮放到設備寬度並在需要時刪除元素。

代碼中提到的站點

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM