[iOS base Control-3.4] Tom Cat

Source: Internet
Author: User

Needs: 1. Click on the button to play the corresponding animation 2. Click on the body part of Tom Cat (head, Feet, tail) show animation 3. The animation currently playing cannot trigger other animations 4. Optimize cache, memory management A. Sequence Frame Animation # #. PNG-formatted files can be accessed without the extension, and can be previewed in the "Images.scassets" group, JPG can only be placed in the support file, and when accessed, write the extension # #. The property bar in Viewcontroller lets you set the size of the storyboard model #3. Drag into the folder to select "Create Groups" to correctly reference, do not select "Create Folder References" 1.Create Groups for any added folders: Add the selected file to the project Grou p, if you select a file, the folder is considered group. The project directory and file path that he added to the folder do not necessarily correspond to one by one. You can delete the file, you can delete the file in the project, you can also delete the file corresponding to the local file.     The folder to which it should be generated is yellow. 2.Create folder references for any added folders: This method creates an index of a folder, and all files in the folder are added to the entire project. The folder that he added corresponds to the project directory and file path that corresponds to one by one. If you want to delete the file, you can delete the file directly into the file directory, and then refresh the directory, and the file will be deleted. This way to add folders is very convenient, you should be in the cocos2d of the project should be used frequently. The folder that should be generated by him is blue #4. Integer placeholder for 0 padding:%02d for two-bit integer, high-discontent with 0 padding 1. Animation execution method
1     // stores multiple pictures that make up animations 2    3     [Self.tom setanimationrepeatcount:1//  default 0 is unlimited 4     [Self.tom setanimationduration:images.count/Framescount]; 5     [Self.tom startanimating];
2. Image caching mechanism & free memory A. Use UIImage *image = [UIImage imagenamed:filename]; store images into a mix, which consumes a lot of memory when loading lots of pictures
1         // imagenamed: There is a cache 2 //         UIImage *image = [UIImage imagenamed:filename]; 3        4         // imagewithcontentoffile: No cache (full path of incoming files) 5         NSBundle *bundle = [NSBundle mainbundle]; 6         NSString *path = [bundle pathforresource:filename Oftype:nil]; 7         UIImage *image = [UIImage Imagewithcontentsoffile:path];
B. Release the image memory
    1];
B. Tom Cat main code (using storyboard drag control mode)
1 #import "ViewController.h"2 3 #defineFramescount 24//Animation Frames/sec4 5 @interfaceViewcontroller ()6@property (Weak, nonatomic) Iboutlet Uiimageview *Tom;7 8-(ibaction) drink;9-(ibaction) knockhead;Ten  One @end A  - @implementationViewcontroller -  the- (void) Viewdidload { - [Super Viewdidload]; -     //additional setup after loading the view, typically from a nib. -      + } -  +- (void) didreceivememorywarning { A [Super didreceivememorywarning]; at     //Dispose of any resources the can be recreated. - } -  - /** Click on the Milk button*/ --(ibaction) Drink { -[Self Runanimationwithname:@"Drink"Andcount: the]; in } -  to /** Click on the head*/ + //in essence, a transparent button with no text is placed in the head. --(ibaction) knockhead { the[Self Runanimationwithname:@"Knockout"Andcount: the]; * } $ Panax Notoginseng /** Run the corresponding animation*/ -- (void) Runanimationwithname: (NSString *) Animationname Andcount: (int) Count { the     if(self.tom.isAnimating)return; +      ANsmutablearray *images =[Nsmutablearray array]; the      for(intI=0; I <= count; i++) { +NSString *filename = [NSString stringWithFormat:@"%@_%02d.jpg", Animationname, I]; -          $         //imagenamed: There is a cache $ //UIImage *image = [UIImage imagenamed:filename]; -          -         //imagewithcontentoffile: No cache (full path of incoming files) theNSBundle *bundle =[NSBundle Mainbundle]; -NSString *path =[bundle Pathforresource:filename Oftype:nil];WuyiUIImage *image =[UIImage Imagewithcontentsoffile:path]; the          - [Images addobject:image]; Wu     } -      AboutSelf.tom.animationImages = images;//stores multiple pictures that make up animations $      -[Self.tom Setanimationrepeatcount:1];//The default 0 is an infinite number of times -[Self.tom setanimationduration:images.count/Framescount]; - [Self.tom startanimating]; A      +[Self.tom performselector: @selector (setanimationimages:) Withobject:nil afterDelay:self.tom.animationDuration +1]; the } -  $  the @end
C. Document comments use block annotations to display comments when the input code is completed automatically/** */

[iOS base Control-3.4] Tom Cat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.