I am a beginner to Swift, so I would probably need some explaining. Please bear with me. I am creating an app that needs to load a .gif
file, but when I run it on the simulator it loads for one second (or even less) and then becomes blank, but the screen itself stays on the page that had the .gif
file on it. I'm not sure why this happens. Can someone explain? Thank you!
Here is the code:
import UIKit
class ViewController: UIViewController {
@IBAction func Burning(sender: AnyObject) {
let imageData = NSData(contentsOfURL: NSBundle.mainBundle().URLForResource("fire", withExtension: "gif")!)
let imageGif = UIImage.gifWithData(imageData!)
let imageView = UIImageView(image: imageGif)
imageView.frame = CGRect(x: 0.0, y:0.0, width:414.0, height: 685.0)
view.addSubview(imageView)
}
@IBAction func Smashing(sender: AnyObject) {
let imageData = NSData(contentsOfURL: NSBundle.mainBundle().URLForResource("water", withExtension: "gif")!)
let imageGif = UIImage.gifWithData(imageData!)
let imageView = UIImageView(image: imageGif)
imageView.frame = CGRect(x: 0.0, y:0.0, width:414.0, height: 685.0)
view.addSubview(imageView)
}
@IBAction func Shredding(sender: AnyObject) {
let imageData = NSData(contentsOfURL: NSBundle.mainBundle().URLForResource("shredder", withExtension: "gif")!)
let imageGif = UIImage.gifWithData(imageData!)
let imageView = UIImageView(image: imageGif)
imageView.frame = CGRect(x: 0.0, y:0.0, width:414.0, height: 685.0)
view.addSubview(imageView)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}