2017-03-08 7 views
1

バッハ.playgroundファイルに表示されるが、灰色です。異なるResult Display Modesをトグルすると助けになりませんでした。A UIImageグレースイフト3遊び場URLSession非同期

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() 

スウィフト3.0でバッハや.playground内の任意UIImageViewをレンダリングするための最良の方法は何ですか?

+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") 

基本的に、画像は遊び場がまだ実行されている間、色あせ表示されます。 needsInfiniteExecutiontrueに設定されているため、常に薄れて表示されます。

関連する問題