How to animate images in Swift? [duplicate]

筅森魡賤 提交于 2021-02-10 19:49:41

问题


I have updated to last version of xcode with ios 8.1 sdk and I get an error ion declaration of my function in:

  @IBOutlet weak var imageAnimation: UIImageView!

  imageAnimation.animationImages = [
        UIImage(named: "5.png"),
        UIImage(named: "4.png"),
        UIImage(named: "3.png"),
        UIImage(named: "2.png"),
        UIImage(named: "1.png")
    ]

The error is: 'Type UIImage? does not conform to protocol 'AnyObject'

How can animate images?

Thanks!


回答1:


Small code example for you. Use array and for loop to do this.

    //add images to the array
    var imagesListArray :NSMutableArray = []
    //use for loop
    for position in 1...5
    {

        var strImageName : String = "c\(position).png"
        var image  = UIImage(named:strImageName)
        imagesListArray.addObject(image)
    }

    self.imageView.animationImages = imagesListArray;
    self.imageView.animationDuration = 1.0
    self.imageView.startAnimating()


来源:https://stackoverflow.com/questions/26584729/how-to-animate-images-in-swift

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!