IOS多媒体-使用UIImageView制作帧动画

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_21153627/article/details/84256655

首先导入一组连续拍摄的图片到资源文件中

创建一个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)

猜你喜欢

转载自blog.csdn.net/qq_21153627/article/details/84256655