On iOS 11, 1. First execute the animation group to execute frame animation in the set picture, 2. Set the picture in the set frame animation, execute frame animation without any problem.
On iOS 10 and iOS 9, you must execute method 2 (first set the picture to set the frame animation, execute the frame animation), otherwise you can’t set the picture after the frame animation.
/// imageViewTo achieve frame animation, the last picture transposition with the right number of open box picture has been received./// /// - Parameters: /// - imageCount: Number of animations/// - imageName: Prefix names for animated images of multiple frames/// - iv: ImageView with frame animation required func ivShowAnimaton(imageCount:Int, imageName:String, iv:UIImageView){ //The following settings are completed after the display picture must be before the animation picture, otherwise iOS 11 will not be set before iv.image = UIImage(named: "xiangzi-attack_66") ///---1.Load images to array var imgArray = [UIImage](); for i in 0..<imageCount{ if let path = Bundle.main.path(forResource: "\(imageName + String(i))", ofType: "png") , let image = UIImage(contentsOfFile: path) { imgArray.append(image) } } ///---2、Adding arrays to UIImageView iv.animationImages = imgArray; ///---3、Set animation duration iv.animationDuration = Double(imgArray.count) * 0.1; ///---4、Duration of animations iv.animationRepeatCount = 1; ///---5、Open the animation iv.startAnimating(); iv.contentMode = .scaleAspectFill }