2017-03-11 1 views
0
import UIKit 
import PlaygroundSupport 
import XCPlayground 

//main window 
let view = UIView(frame: CGRect(x:0, y: 0, width: 480, height: 320)) 
//array of images 
let animationPictures: [UIImage] = 
[ 
     UIImage(named: "first.png")!, 
     UIImage(named: "second.png")! 
] 
var animationBkg = UIImageView() 
animationBkg.animationImages = animationPictures; 
animationBkg.animationDuration = 0.5 
animationBkg.startAnimating() 

Hier ist der Code, den ich derzeit habe. Das Ziel ist es, diese zwei Bilder hintereinander als Animation zu spielen, aber es funktioniert nicht. In der Vorschau meines Codes ist nur ein schwarzes Quadrat vorhanden.UIImageView Animation Spielplatz

+0

Haben Sie versucht, 'importieren XCPlayground; XCPlaygroundPage.currentPage.needsIndefiniteExecution = true'? –

+0

Ich aktualisierte den Code –

+0

Ich fügte hinzu, in den Dingen, die Sie sagten, und es warf einen Fehler auf dieser zweiten Zeile des Codes –

Antwort

0
let animationPictures: [UIImage] = 
[ 
     UIImage(named: "first.png")!, 
     UIImage(named: "second.png")! 
] 
//animation 
var animationView = UIImageView(frame: CGRect(x: CGFloat(0), y: CGFloat(0), width: CGFloat(480), height: CGFloat(320))) 
animationView.animationImages = animationPictures 
animationView.animationDuration = 1.5 
animationView.animationRepeatCount = 0 
animationView.startAnimating() 
view.addSubview(animationView) 

Ich fand eine Lösung für mein eigenes Problem. Danke für die Hilfe