2017-03-08 24 views
1

Bach顯示在.playground文件中,但灰色。切換不同的Result Display Modes沒有幫助。Swift 3遊樂場URLSession中的UIImage灰色異步

enter image description here

import UIKit 
import PlaygroundSupport 

PlaygroundPage.current.needsIndefiniteExecution = true 
URLCache.shared = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil) 

var theImage = UIImageView() 
let urlNew = NSURL(string: "https://upload.wikimedia.org/wikipedia/commons/6/6a/Johann_Sebastian_Bach.jpg") 


let task = URLSession.shared.dataTask(with: urlNew! as URL) { (data, response, error) -> Void in 

    if error != nil { 
     print("thers an error in the log") 
    } else { 

     DispatchQueue.main.async() { 
      let image = UIImage(data: data!) 
      theImage.image = image 
     } 
    } 

} 

task.resume() 

什麼是呈現巴赫或任何UIImageView與雨燕3.0 .playground的最佳方式?

+0

你到目前爲止嘗試過什麼?很明顯,它正在下載適當的圖像,它可能只是遊戲場中的UI錯誤。您還應該能夠跳過'UIImageView'並直接顯示'UIImage'。 –

+0

我試過了。將「UIImageView」中的代碼更新爲「UIImage」對灰色陰影沒有影響。 – Eric

+0

我剛纔不在我的電腦前,但我會在今晚晚些時候重現問題。 –

回答

3

我想通了,你遇到的問題,並創建了一個操場這裏來說明:https://github.com/dtweston/Bach.playground

import UIKit 
import PlaygroundSupport 

// Toggle the code below to fade the image out or display it properly 
//PlaygroundPage.current.needsIndefiniteExecution = true 

let image = UIImage(named: "Johann_Sebastian_Bach.jpg") 

基本上,而操場上仍在運行的圖像變淺。由於您的needsInfiniteExecution設置爲true,它總是顯得褪色。