Swift 2 - 从URL加载图像或视频时显示加载视图

时间:2016-01-10 13:55:26

标签: uiimageview swift2 loading mpmovieplayercontroller

我正在尝试从网址中提取图片时显示加载视图。我知道如何使用UIWebview执行此操作但是,我无法使用UIImageViewMPMoviePlayerController找到实现此目的的方法。

要从Url加载图片或视频,请使用:

 let pictureURL = NSURL(string: pictureToDisplay!)
 newsImage.hnk_setImageFromURL(pictureURL!)

let videoURL = NSURL(string: sourceToDisplay!)
moviePlayer = MPMoviePlayerController(contentURL: videoURL!)

有没有办法在加载网址时显示和隐藏加载视图loading_view.hidden = false - loading_view.hidden = true

1 个答案:

答案 0 :(得分:0)

使用NSURLConnectionDelegate解决。

func requestNSURLconnection(url: NSURL){
        let request: NSURLRequest = NSURLRequest(URL: url)
        let connection: NSURLConnection = NSURLConnection(request: request, delegate: self, startImmediately: true)!
        connection.start()
    }


    func connectionDidFinishLoading(connection: NSURLConnection!)
    {

        print("finishedLoading")
    }