我已经使用ios 8.1 sdk更新到xcode的最新版本,并且我得到了函数的错误声明:
@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'
如何动画图像?
谢谢!
答案 0 :(得分:8)
您的小代码示例。使用array和for循环来执行此操作。
//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()