This example for you to share the iOS using Uiimageview control animation method for your reference, the specific content as follows
Add 40 tomcat pictures to the list of resources: The name is cat_eat0000.jpg to Cat_eat0039.jpg.
1, define the required controls
define buttons, picture controls, variable array objects
UIButton *actionbuttom;
Uiimageview *imagemove;
Nsmutablearray *imgsarray;
2. Initialize each control
Image Animation//initialization uiimageview, size and view of the same size imagemove = [[Uiimageview alloc]initwithframe:self.view.frame];
Sets the initialization picture of the Uiimageview imagemove.image = [uiimage imagenamed:@ "cat_eat0000.jpg"];
Load the Uiimageview onto the page [Self.view Addsubview:imagemove];
Sets the interactivity of the Uiimageview to Yes imagemove.userinteractionenabled = yes;
Create Function button//Initialize button Actionbuttom = [[UIButton alloc]initwithframe:cgrectmake (100, 680, 218, 50)];
Set button background color Actionbuttom.backgroundcolor = [Uicolor Yellowcolor];
Set button title [Actionbuttom settitle:@ "start playing" forstate:uicontrolstatenormal];
Set button text color [Actionbuttom settitlecolor:[uicolor blackcolor] forstate:uicontrolstatenormal]; To add a trigger event for a button [Actionbuttom addtarget:self action: @selector (startmove:) forcontrolevents:uicontroleventtouchupinside
];
Add the button to the page [Imagemove Addsubview:actionbuttom];
Initializes the variable group, which is used to store the picture Imgsarray = [[Nsmutablearray alloc]initwithcapacity:40];
The loop gets 40 pictures from the resource and adds it to the Imgsarray. for (int x=0; x<40; x + +) {NSString *imgname = [NSString stringwithformat:@ "Cat_eat00%.2d.jpg", X];
UIImage *img = [UIImage imagenamed:imgname]; [Imgsarray addobject:img];
3, set the button to trigger animation playback
Button trigger event
-(void) Startmove: (ID) sender{
// Set animation length
imagemove.animationduration = 2; sets the animation picture source for the picture array
imagemove.animationimages = Imgsarray; Set animation Repeat number, 0 is infinite loop, 1 is repeat 1 times
imagemove.animationrepeatcount = 1; start playing
[Imagemove startanimating];
}
The above is the entire content of this article, I hope to learn how to use Uiimageview control to make animation help.