Tom learns IOS (4) half an hour of UI to get Tom and iosui

Source: Internet
Author: User

Tom learns IOS (4) half an hour of UI to get Tom and iosui

Let's talk about the effect first.
Project source material: Tomcat game code iOS material http://blog.csdn.net/u013357243/article/details/44457357

Tomcats, once popular, are actually quite easy to create.
All functions are implemented. (The key is materials. You can add me without materials)
New users can quickly complete tom's ios app.
I have done android, and said that the android party is very painful ....




Then you need to prepare the materials...

Drag the control, because this project does not use a lot, and it is too tired to write code. It is worth the candle, if you are interested, thank you for your pure code ui exercises.
Cat learning IOS (3) UI-code-only UI-Image Viewer

Drag and Drop controls. What about those items? view images.

It's just these things. The place of that name is amazing in the code.
In addition, the tag attribute of UIButton has been added with amazing numbers.
If you do not drag the control, you can view the Hello World and addition calculator of IOS (1) UI

The code below

Code
// Call the button listening method-(IBAction) tomAction :( UIButton *) button {[self tomAnimationWithName: button. currentTitle count: button. tag];} // Let the Tom change. name indicates the name of the action to be executed. count indicates the number of images.-(void) tomAnimationWithName :( NSString *) name count :( NSInteger) count {// if the animation is being played, if (self. tom. isAnimating) {return ;}// sequence Frame Animation plays a group of images // array NSMutableArray * arrayM = [NSMutableArray array] of the specified animation image; // Add the animation clip for (int I = 0; I <count; I ++) {NSString * imageName = [NSString stringWithFormat: @ "%@_%02d.jpg", name, i]; // UIImage * image = [UIImage imageNamed: imageName]; // obtain the full path name NSString * path = [[NSBundle mainBundle] pathForResource: imageName ofType: nil]; UIImage * image = [UIImage imageWithContentsOfFile: path]; arrayM [I] = image ;}; // put the operated UIImage image in the animationImages of UIImageView and put the Image array in the Tom Control self. tom. animationImages = arrayM; // The setting is executed once [self. tom setAnimationRepeatCount: 1]; // sets the execution time self. tom. animationDuration = arrayM. count * 0.075; // start executing the animation [self. tom startAnimating]; // After the animation ends, clear the animation array [self. tom specified mselector: @ selector (setAnimationImages :) withObject: nil afterDelay: self. tom. animationDuration];}

Here is the code we want to use. Remember to connect the circles in front of the Code to the ui. Otherwise, it will be useless if you do not click it.
Do you believe that Tom has completed just a few lines of code. Most of them are comments without a single screen.

Let's talk about what we should pay attention.
Memory Management is particularly important here. We do not recommend using
[UIImage imageNamed: name];
Instead, the following code is used:
[UIImage imageWithContentsOfFile: path];
In this way, we can release the memory more perfectly.
It is very important to have an internal ios. The customer experience has always been a reminder from Apple (it is said that android5.0 or 5.1 is missing again... In fact, android is really good. I don't mean anything about black android. I just hope android can grow stronger and better .)

Reconstruction _ image instantiation

Refactoring-extract code
Method:
1> duplicate code is copied to the new method.
2> adjust parameters as needed

Image instantiation

ImageNamed: recommended by the system. However, the system is responsible for the release after image instantiation.
You cannot use the imageNamed method to release images by yourself!

ImageWithContentsOfFile

Tip: imageWithContentsOfFile cannot be used if the image is placed in Images. xcassets.
Do not store enlarged Images in Images. xcassets. Do not use Images that are not commonly used.

PS1. if you want to learn more, add me znycat (where can you see it? learning materials are free of charge, including videos, ppt, projects, project materials .....) . ---- I cannot finish learning too much. I want to find a few people to join me. Welcome to the discussion.

Related Article

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.