functional analysis
Click the corresponding button , Let Tom show the corresponding animation

Step analysis
1, build UI Interface
2, Click the monitor button
3, Execute the corresponding animation according to the button you click

Knowledge points :
1,UIImageView Use of frame animation
2,UIImage Of 2 Loading methods
3, Encapsulation extraction of duplicate code
4, How to write document notes

UIImageView Frame animation related attributes and methods
@property(nonatomic,copy) NSArray *animationImages;
Sequence frame image array to play ( It's all in it UIImage object , The pictures inside will be displayed in order )
@property(nonatomic) NSTimeInterval animationDuration;
The duration of the frame animation
@property(nonatomic) NSInteger animationRepeatCount;
The number of times frame animation is executed ( The default is infinite loop )
- (void)startAnimating;
Start frame execution animation
- (void)stopAnimating;
Stop executing frame animation
- (BOOL)isAnimating;
Is frame animation in progress

UIImage Of 2 Loading methods
Mode 1 : There is a cache ( The memory occupied by the picture will stay in the program all the time )
+ (UIImage )imageNamed:(NSString )name;
name Is the file name of the picture

Mode 2 : No cache ( The memory occupied by the image will be cleared after some specific operations )
+ (UIImage )imageWithContentsOfFile:(NSString )path
- (id)initWithContentsOfFile:(NSString *)path;
path It's the full path of the picture
Mode 2 is more optimized for memory

Encapsulation extraction of duplicate code :
1, When a code is repeated in multiple parts of the program , It makes the program stinky and long , When the structure of the code needs to be modified , Every place where this code appears has to be modified , This leads to poor scalability of the program
2, therefore , To extract recurring code into a method , Call the method where you need this code

How to extract code
1. Put the same code in a method
2. Pass in different values as method parameters

Code brief :( Do not drag controls , Using pure code interface )
#import "HMViewController.h" @interface HMViewController () @property (weak,
nonatomic) IBOutlet UIImageView *tom; @end @implementation HMViewController /**
Refactoring code : 1, Copy the duplicate code into the new method 2, Adjust the method as needed About image instantiation UIImage UIImageView imageName:
System recommended , However, the system is responsible for the release of images after instantiation If you want to release the pictures yourself, you can't use them imageName method ! UIImage *image = [UIImage
imageNamed:imageName]; Alternative methods : [UIImage imageWithContentsOfFile:<#(NSString
*)#>] be careful : As soon as we meet ContentsOfFile Full path must be used !! Tips : If placed in Images.xcassets
Pictures in ( Store frequently used pictures ), out of commission imageWithContentsOfFile: Temporary use of large pictures on Supporting Files */ -(
void)tomAnimationWithName:(NSString *)name count:(NSInteger)count{ // Judge whether it is in animation if
([self.tom isAnimating]) return; // Animation image array NSMutableArray *imageArray = [
NSMutableArray array]; int i; for (i = 0 ; i< count ; i++) { NSString
*imageName = [NSString stringWithFormat:@"%@_%02d.jpg",name,i]; //UIImage
*image = [UIImage imageNamed:imageName]; NSString *path = [[NSBundle
mainBundle] pathForResource:imageName ofType:nil]; UIImage *image = [UIImage
imageWithContentsOfFile:path]; [imageArray addObject:image]; }// Set animation array self.tom
.animationImages = imageArray; // One more time self.tom.animationRepeatCount = 1; // Animation duration
self.tom.animationDuration = self.tom.animationImages.count * 0.075; // Start animation [
self.tom startAnimating]; // // Release the array after clicking the end of the event // self.tom.animationImages = nil; [
self.tom performSelector:@selector(setAnimationImages:) withObject:nil
afterDelay:self.tom.animationDuration]; } //currentTitle The current title text of the button can be removed -(IBAction
)tomAction:(UIButton *)button{ [self tomAnimationWithName:button.currentTitle
count:button.tag]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any
additional setup after loading the view, typically from a nib. } - (void
)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any
resources that can be recreated. } @end
Screenshot of running results :

©2019-2020 Toolsou All rights reserved,
c Language implementation 《 Student management system 》 No hole is the future of mobile phone ? There are still many problems to be solved Junior , A little sense , Just for mutual encouragement How to use Vue Used in Echarts Visual Library The 11th Blue Bridge Cup Java The second provincial competition B Group part Python- be based on OpenCV Contour fill for flooding algorithm hole filling 【C#】 The realization of student achievement information management system List Common interview questions in the collection and simple ideas China Mobile Science Popularization : Why do mobile networks call “ Cellular mobile network ”【Golang Basic series 10 】Go language On conditional sentences if