I have an animation using a UIImageView
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = 1;
myAnimatedView.animationRepeatCount = 1;
[myAnimatedView startAnimating];
How can I tell to animation to stop at the last frame or to be visible last frame of the series of images?
Thank you in advance
the image property on the UIImageView class has the following docs: "If the animationImages property contains a value other than nil, the contents of this property are not used."
So the trick to hold on the last frame of an animation in iOS4 is to first set the image property to that last frame (while animationImages is still nil), then set the animationImages property and call startAnimating. When the animation completes, the image property is then displayed. No callback/delegate needed.
You can set image of last frame to your UIImageView instance and then when animation will finish last frame image remains visible. Here is the code:
// create your array of images
NSArray *images = @[[UIImage imageNamed:@"video1.png"], [UIImage imageNamed:@"video2.png"]];
UIImageView *imageView = [UIImageView new];
imageView.image = images.lastObject;
imageView.animationImages = images;
imageView.animationDuration = 1.0; // seconds
imageView.animationRepeatCount = 1;
[imageView startAnimating];
After the animation finishes you can set your UIImageView image to the last frame of your animation.
myAnimatedView.image = [myAnimatedImages objectAtIndex:myAnimatedImages.count - 1]
I don't think there is a delegate method that would notify you on animationFinish event so you would need to start a NSTimer
with same duration as the animation to get the notification.
UIImageViewAnimation documentation
Swift version will be as given below but in objective-c logic will be same
you can hack it just setting the image
of the UIImageView
to the last image of the images array. just before the code of animation, like imageView.image = arrayOfImage.last
the whole logic is given below
imageView.image = arrayOfImage.last //(this line create magic)
imageView.animationImages = arrayOfImage
imageView.animationDuration = 1.0
imageView.animationRepeatCount = 1
imageView.startAnimating()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With