Animated uibutton applying images quickly
I want to apply an animation effect by changing two images to a button in turn. I have applied the following code but could not see the animation effect. I have applied IBOutlets correctly.
var image1:UIImage = UIImage(named: "img_mic_off")!
var image2:UIImage = UIImage(named: "img_mic_on")!
btnRecord.imageView?.animationImages = [image1,image1]
btnRecord.imageView?.animationDuration = 1.0
btnRecord.imageView!.startAnimating()
Please help me to solve the problem why it doesn't work with the given code. Thanks in advance.
+3
source to share
2 answers
See what I have done. The images change. So I hope this is what you really need.
var image1:UIImage = UIImage(named: "img_mic_off")!
var image2:UIImage = UIImage(named: "img_mic_on")!
btn.setImage(image1, forState: UIControlState.Normal)
btn.imageView!.animationImages = [image1, image2]
btn.imageView!.animationDuration = 1.0
btn.imageView!.startAnimating()
+6
source to share
The animation property simply loops through the array of images and changes them at intervals of the durationInSeconds / numberOfImagesInArray.
So, to have smooth image animations, you need a set of transition intermediate images.
The larger the number of images in the set, the smoother the animation.
+1
source to share