如何在 Swift 中为图像设置动画? [英] How to animate images in Swift?

查看:41
本文介绍了如何在 Swift 中为图像设置动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用 ios 8.1 sdk 更新到最新版本的 xcode,并且在以下位置收到了我的函数的错误离子声明:

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

错误是:'键入 UIImage?不符合协议AnyObject"

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

如何为图像制作动画?

谢谢!

推荐答案

给你的小代码示例.使用数组和 for 循环来做到这一点.

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

这篇关于如何在 Swift 中为图像设置动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆