加载请求后,我无法加载动画,也无法将其删除

时间:2019-08-29 09:31:01

标签: ios swift wkwebview gif

我在应用程序的本机部分做一些事情。然后,当我从服务器获取sessionID时,将其设置为WKWebView。然后,我将网页加载到webview本身。问题是,我使用了名为“ didfinish”的功能来播放gif。该函数有效,每次都会调用,但是当我尝试停止gif时,它对我的​​图像视图显示nil。

我将imageview放在一个WKWebview的视图上方,直到该用户完全看到为止,该用户看不到一个空白视图。

override func viewDidLoad() {
        super.viewDidLoad()
        ...some code...
        imageViewForAnimation.loadGif(named:"gif")
        loadWeb()
}
func loadWeb(){
        setCookie()
        view=self.webview
        webview?.load(URLRequest(url: URL(string: lastURL)!))
        self.webview.navigationDelegate=self
}
func setCookie(){
        print("session id is:\(session_id)")
        let cookie = HTTPCookie(properties: [
            .domain: "mywebpage.com",
            .path: "/",
            .name: "sessionID",
            .value: "\(session_id)",
            .secure: "TRUE",
            .expires: NSDate(timeIntervalSinceNow: 31556926)
            ])!
        let websitedataStorage=WKWebsiteDataStore.nonPersistent()
        websitedataStorage.httpCookieStore.setCookie(cookie) {
        }
        let configuration=WKWebViewConfiguration()
        configuration.websiteDataStore=websitedataStorage
        webview=WKWebView(frame: self.view.frame, configuration: configuration)
}

一切正常,没有任何gif或任何其他内容。我想要的是,如果页面准备好了

func webView(_ webView: WKWebView,
                 didFinish navigation: WKNavigation!) {
        self.imageViewForAnimation.image=nil   //for stopping animating
        self.coverViewOnTopOfWebView.alpha=0   //show web now

 }

我得到的错误是

  

线程1:致命错误:意外地发现nil而隐式   展开一个可选值

在didFinish函数中。为了播放gif,我使用了此类

https://github.com/swiftgif/SwiftGif/blob/master/SwiftGifCommon/UIImage%2BGif.swift

谢谢大家的帮助和建议。

1 个答案:

答案 0 :(得分:0)

您在使用PHP Fatal error: Uncaught SoapFault exception: [soap:Server] getInterestAndExchangeRates failed: Please check inparameters in [path]_(does_not_work).php:22 Stack trace: #0 [path]_(does_not_work).php(22): SoapClient->__soapCall('getInterestAndE...', Array) #1 {main} thrown in [path]_(does_not_work).php on line 22 方法的以下代码中出错。

Orville Wright 21 July 1988
Rogelio Holloway 13 September 1988
Marjorie Figueroa 9 October 1988
Debra Garner 7 February 1988
Tiffany Peters 25 July 1988
Hugh Foster 2 June 1988
Darren Christensen 21 January 1988
Shelia Harrison 28 July 1988
Ignacio James 12 September 1988
Jerry Keller 30 February 1988

以上代码会将nil置于Read the file DOB.txt create a loop that will go over the contents being read from the File display every line being read ( this will have the name and the DOB of the students) Use string indexing to get the first name and the 2nd name assign this to a variable and print the first name and surname For example something like this first_name = name[0] + name[1] Keep in mind the name is the iterator that will be looping over the file we are reading too. DO the same to the DOB ( use string indexing to get the DOB of the student ) Counter for numbering each name counter for numbering each surname open file for reading store contents of file in the form of lines loop through contents split each line into words access the word and charcaters using indexing 内的所有其他控件。 而不是将loadWeb()分配给view=self.webview ,您应该从情节提要中添加它,或以编程方式在以下视图中添加它:

view

self.webView

哪个更适合您?