#import "ViewController.h"
@interface Viewcontroller ()
@property (Weak, nonatomic) Iboutlet Uiimageview *tomimageview;
@end
@implementation Viewcontroller
Knock on Tom's cat's head. Premise: A series of animations have been imported.
(ibaction) btnknockoutonclicked: (UIButton *) sender{
[Self tomimatewith:@ "KnockOut" imagecount:81];
}
Tom plays birds. Premise: The animation about the bird has been imported.
(ibaction) Eatonclick: (UIButton *) sender{
[self.tomimatewith:@ "Eat" iamgecout:40];
}
Animation Execution method
(void) Tonanimatewith: (NSString *) fileName Iamgecount:(Nsinteger) imagecout{
0. If you create picture data
if (self.tomImageView.isAnimating) {
Return
}
1. First create an array of images
Nsmutablearray *tomimages = [Nsmutablearray Arry];
for (int i=0;i<imagecout;i++) {
NSString *imagename = [NSString stringwithformat:@ "%1.jpg", FileName, I];
NSString *path = [[NSBundle mainbundle] Pathforresource:imagename Oftype:nil];
UIImage *image = [UIImage Imagewithcontentsoffile:path];
[Tomimages Addobject:image];
}
2 Setting up the animation process
2.1 Adding an animated array of images
[Self.tomimageview Setanimationimages:tomimages];
2.2 Setting the time for animation execution
[Self.tomimagesview setanimationduration:self.tomimageview.animationimages.cout*0.1];
2.3 Set the number of times the animation executes
[Self.tomimagesview setanimationrepeatcout:1];
2.4 Set Animation to start
[Self.tomimagesview startanimating];
3. Empty the array after animation technology
[Self perfomselector: @selector (setanimationimages) Withobject:nil afterDelay:self.tomImagesView.animationDuration ] ;
}
Tom Cat Game Core Code IOS/OBJECTIVE-C