IOS development practice ----- tomcat, ios practice ----- tom

Source: Internet
Author: User

IOS development practice ----- tomcat, ios practice ----- tom

Project name: Tomcat

Project knowledge: UIImageView control animation playback

:

 

 

Start Project

 

I,

(1) Add a project and add a UIImageView on the storyboard.

The layout is full of ViewControl.

(2) Add the default image of UIImagView, which is the normal status of Tom.

(3) start to write the background code and select the paging mode.

(4) Tom touch point Decomposition

Tom clicks the header, chest, foot, and six icons to make the corresponding action. In fact, the nine core codes are the same. Here I only write the code in the header, and the rest is left for the readers to think about.

(6) Add a Button to the Tom header. When the Button is reached, the head action is triggered.

Set the properties of the Button to disappear the text of the Button.

(7) connect and write the processing code

Add a function in the TouchHead_Click function.

For (int I = 0; I <80; I ++)

{

// Add images cyclically

NSString * imgName = [NSString stringWithFormat: @ "knockout_42502d.jpg", I];

NSString * path = [[NSBundle mainBundle] pathForResource: imgName ofType: nil];

UIImage * img = [UIImage imageWithContentsOfFile: path];

[ImgArray addObject: img];

[Self LoadImageWithClearImage];

}

 

You also need to write two self-built functions,

1,-(void) ClearImage; clear the image

2,-(void) LoadImageWithClearImage // load the image and clear the image

The details are as follows:

-(Void) ClearImg

{

Self. ImageCat. image = nil;

[ImgArray removeAllObjects];

}

-(Void) LoadImageWithClearImage

{

// Set the animation Source

[Self. ImageCat setAnimationImages: imgArray];

// Set the number of animation repetitions

[Self. ImageCat setAnimationRepeatCount: 1];

// Set the animation playback speed

[Self. ImageCat setAnimationDuration: imgArray. count * 0.1];

// Sets the function for executing the animation after playback.

[Self. ImageCat extends mselector: @ selector (ClearImg) withObject: nil afterDelay: self. ImageCat. animationDuration];

// Start the animation

[Self. ImageCat startAnimating];

}

The core code has been fully written here, and the Code for the next eight actions is basically the same.

Ii. Summary of ideas

Defines a global NSMutableArray as an image storage array. When I click "press the header", the animation loading and cleanup will be triggered.

The details are as follows:

// I is the number of images

For (int I = 0; I <80; I ++)

{

// Add images cyclically

NSString * imgName = [NSString stringWithFormat: @ "knockout_42502d.jpg", I];

NSString * path = [[NSBundle mainBundle] pathForResource: imgName ofType: nil];

UIImage * img = [UIImage imageWithContentsOfFile: path];

[ImgArray addObject: img];

}

[Self LoadImageWithClearImage];

 

When I load the image, I should start the animation. However, you must set the animation before starting the animation.

Set the animation source ----- set the number of animation repetitions --- set the animation speed -- set the animation end to the executed function -- set the start Animation

The Code is as follows:

// Set the animation Source

[Self. ImageCat setAnimationImages: imgArray];

// Set the number of animation repetitions

[Self. ImageCat setAnimationRepeatCount: 1];

// Set the animation playback speed

[Self. ImageCat setAnimationDuration: imgArray. count * 0.1];

// Sets the function for executing the animation after playback.

[Self. ImageCat extends mselector: @ selector (ClearImg) withObject: nil afterDelay: self. ImageCat. animationDuration];

// Start the animation

[Self. ImageCat startAnimating];

 

 

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.