问题
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