Bach显示在put()
文件中,但显示为灰色。切换不同的.playground
没有帮助。
Result Display Modes
使用Swift 3.0在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()
中呈现Bach或任何UIImageView
的最佳方法是什么?
答案 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
,因此它总是显得褪色。