首先导入一组连续拍摄的图片到资源文件中
创建一个UIImage数组并将图片添加到数组中
var images = [UIImage]()
for i in 1...19 {
images.append(UIImage(named: "animation\(i)")!)
}
设置动画属性。并开始动画
let imageView = UIImageView(frame: CGRect(x: 0, y: 60, width: 335, height: 253))
//设置图像视图的动画图片属性
imageView.animationImages = images
imageView.animationDuration = 5
imageView.animationRepeatCount = 0
imageView.startAnimating()
self.view.addSubview(imageView)