- The first step is to create a Uiiimageview object in storyboard.
@property (strong,nonatomic) Iboutlet uiimageview *tomimageview;
- The second step creates an array of pictures.
// Create an array of images
nsmutablearray *tomimages = [nsmutablearrayArray ];
// path of the picture
nsstring *imagename = [nsstringstringwithformat: @ "%@_%02d.jpg" , filename,i];
// This method has a memory overflow and is generally not used
//UIImage *image = [UIImage imagenamed:imagename];
// This method does not have memory overflow
nsstring *path = [[nsbundlemainbundle] Pathforr Esource: imageNameofType:nil];
UIImage *image = [UIImageimagewithcontentsoffile:p Ath];
[tomimages addobject: image];
- The
- third adds a picture array to the Uiimageview object.
// add an array of animation execution
[ self . tomimageview setanimationimages :tomimages];
- The
- sets the execution time for this animation.
// Add time for animation execution
[ self tomimageview setanimationduration : Self tomimageview animationimages count * 0.1
- Sets the number of times the animation executes.
// Add the number of animation executions
[self. Tomimageview setanimationrepeatcount:1];
- Start animation
// start animation
[self. Tomimageview startanimating];
- Releases the memory occupied by the animated picture.
// method One , empty the array
//[Self.tomimageview Performselector: @selector (clearimage) Withobject:nil afterDelay:self.tomImageVi Ew.animationduration];
// method Two , reset setanimationimages
[self. Tomimageview performselector:@selector(setanimationimages:)withobject : Nil afterdelay:self. Tomimageview . animationduration ];
-(void) clearimage {
self. Tomimageview . animationimages = Nil ;
}
Animating with Uiimageview