" .gif要点"文件加载然后在1秒后消失

时间:2016-08-02 14:50:36

标签: ios swift gif

我是 Swift 的初学者,所以我可能需要一些解释。请多多包涵。我正在创建一个需要加载.gif文件的应用程序,但是当我在模拟器上运行它加载一秒钟(甚至更少)然后变为空白,但屏幕本身仍保留在页面上它上面有.gif个文件。我不确定为什么会这样。谁能解释一下?谢谢!

以下是代码:

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.
    }


}

0 个答案:

没有答案