Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 加载页面时UIWebView白色闪烁_Html_Swift_Uiwebview - Fatal编程技术网

Html 加载页面时UIWebView白色闪烁

Html 加载页面时UIWebView白色闪烁,html,swift,uiwebview,Html,Swift,Uiwebview,我已经为iOS构建了一个WebApp。当我单击/点击移动到某个页面时,例如从page-index.html移动到page2.html,页面会闪烁白色。你知道为什么,以及如何解决这个问题吗 这些网站在浏览器(Safari、IE、Firefox和Chrome)中运行非常出色,但不是作为一个应用程序 我的代码是: import UIKit class ViewController: UIViewController { @IBOutlet weak var webView: UIWebView!

我已经为iOS构建了一个WebApp。当我单击/点击移动到某个页面时,例如从page-index.html移动到page2.html,页面会闪烁白色。你知道为什么,以及如何解决这个问题吗

这些网站在浏览器(Safari、IE、Firefox和Chrome)中运行非常出色,但不是作为一个应用程序

我的代码是:

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.


    webView.loadRequest(NSURLRequest(URL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("index", ofType: "html")!)))


}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


}

试试我的代码会帮你的

步骤1:将
UIWebView
UIActivityIndicatorView
提取到视图控制器。 步骤2:将
UIWebView
委托给viewController,并为
UIWebView
UIActivityIndicatorView
创建插座

步骤3:选择视图控制器上的
UIActivityIndicatorView
,然后转到属性检查器->活动指示器视图->检查动画,并在行为停止时隐藏

步骤4:将以下代码添加到
ViewController

import UIKit

class ViewController: UIViewController,UIWebViewDelegate{

    @IBOutlet var loader: UIActivityIndicatorView!
    @IBOutlet var webView: UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.automaticallyAdjustsScrollViewInsets = false //to avoid auto scrolling.
        functionOfWebView()

    }

    func functionOfWebView()
    {
        let URL = NSURL(string: "http://www.google.com")
        //let URL = NSBundle.mainBundle().URLForResource("index", withExtension: "html")  //For local html file(index.html) with local file hyperlink(file.html) see on video tutorial
        let request = NSURLRequest(URL: URL!)
        webView.loadRequest(request)
    }

    func webViewDidStartLoad(webView: UIWebView)
    {
        loader.startAnimating()
    }

    func webViewDidFinishLoad(webView: UIWebView)
    {
        loader.stopAnimating()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

    }


}
在Swift 3.0中

import UIKit

class ViewController: UIViewController,UIWebViewDelegate{

    @IBOutlet var loader: UIActivityIndicatorView!
    @IBOutlet var webView: UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()

        self.automaticallyAdjustsScrollViewInsets = false //to avoid auto scrolling.
        functionOfWebView()
    }

    func functionOfWebView()
    {
        let URL = NSURL(string: "http://www.google.com")
        //let URL = Bundle.main.url(forResource: "index", withExtension: "html")  //For local html file(index.html) with local file hyperlink(file.html) see on video tutorial
        let request = NSURLRequest(url: URL! as URL)
        webView.loadRequest(request as URLRequest)
    }

    func webViewDidStartLoad(_ webView: UIWebView)
    {
        loader.startAnimating()
    }

    func webViewDidFinishLoad(_ webView: UIWebView)
    {
        loader.stopAnimating()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}


如果您对使用本地html文件感到困惑,请参见此

为什么将
alpha
设置为0?只是为了测试它。我想也许它解决了问题。所以,即使没有
alpha
你的
webView
也会闪烁?什么是闪动?闪动我指的是“闪动”/“闪动”页面。当我点击一个按钮从pageA.html移动到pageB.html时,在完全显示页面之前,它的第一个“闪光”/“闪烁”。它不会立即显示pageB.html。。在inspector中,我将UIWebView的背景设置为白色,因此它会闪烁白色。。当我把它设为红色时,它会闪烁成红色。。但是如果我将其设置为“透明”且不透明度为零,它也会闪烁/闪烁为灰色。谢谢你的代码。它可以工作,但对于我的网站来说,加载需要很长时间。我的网站是一个单页的网站,有很多部分/面板,非常大。高度为38400px(768px*50)。链接是锚链接。**2016-08-04 11:36:38.952 webApp[3058:3565120]应用程序传输安全已阻止明文HTTP(HTTP://)资源加载,因为它不安全。可以通过应用程序的Info.plist文件配置临时异常。2016-08-04 11:36:41.970 webApp[3058:3565039]收到内存警告。2016-08-04 11:36:42.166 webApp[3058:3565039]收到内存警告。**请查看Youtube教程:)我在该视频上显示了您所需的内容。非常感谢您的所有努力!我已经观看了视频并在我的Xcode项目中添加了代码,但闪烁/闪烁问题仍然存在:(哎哟!我没有得到那种效果!因此编码是正确的。请检查您的系统并检查它在iOS设备上的输出:):)每当我单击按钮或锚链接时,闪烁或闪烁都会出现../每次需要重新加载页面时:/