iOS Development UI Chapter-ios three simple animation settings in development

Source: Internet
Author: User

iOS Development UI Chapter-ios three simple animation settings in development

"In iOS development, animations are cheap"

First, the end-to-end animation

code example:

1 //beginanimations indicates that subsequent code will "participate in" the animation2 3 [UIView Beginanimations:nil context:nil];4 //Set Animation duration5[UIView setanimationduration:2.0];6     7Self.headImageView.bounds =rect;8 9     //Commitanimations, commits and generates animations for all animations after BeginAnimationTen[UIView commitanimations];
View Code

Note: If you just modify the properties of the control, it is convenient to use the end-to-back animation, but it is not so convenient if you need to do subsequent processing after the animation is finished.

Second, block code blocks animation

code example:

1  // a simple animation effect 2     [UIView animatewithduration:2.0 animations:^{3         showlab.alpha=0; 4     } completion:^(BOOL finished) {5        [Showlab Removefromsuperview]; 6     }];

Description

(1) in the actual development of the more commonly used block code blocks to handle animation operations.

(2) block animation is relatively flexible, especially important is the ability to write animation-related code together, easy to read and understand the code.

Three, sequence frame animation (with a simple Tom cat animation example)

Import pre-prepared footage and connect the Uiimageview and button buttons.

code example:

1-(ibaction) Eat {2     3Nsmutablearray *arraym=[Nsmutablearray array];4      for(intI=0; i< +; i++) {5[Arraym addobject:[uiimage imagenamed:[nsstring stringWithFormat:@"eat_%02d.jpg", I]];6     }7     //set up an animated array8 [Self.tom Setanimationimages:arraym];9     //set the number of animations to playTen[Self.tom Setanimationrepeatcount:1]; One     //Set animation playback time A[Self.tom setanimationduration: +*0.075]; -     //Start Animation - [Self.tom startanimating]; the}
View Code

Click the button, you can perform the animation, the effect is as follows:

Iv. Supplementary Knowledge

1. Materials in the Images.xcassets

(1) Only images in PNG format are supported

(2) The image only supports [UIImage imagenamed] instantiation, but cannot be loaded from the bundle

(3) At compile time, all files in Images.xcassets will be packaged as assets.car files

2. Uiimageview Sequence frame animation (need to consider program performance, release data)

0. Are you animating

[Self.tom isanimating];

1. Set up an array of pictures

[Self.tom Setanimationimages:arraym];

2. Set the animation duration by default to play 30 pictures per second

[Self.tom SetAnimationDuration:arrayM.count * 0.075];

3. Set the number of animations to repeat, default to 0, infinite loop

[Self.tom setanimationrepeatcount:1];

4. Start animation

[Self.tom startanimating];

5. Empty the animated array after the animation has finished playing

[Self.tom performselector: @selector (setanimationimages:) withObject:nilafterDelay:self.tom.animationDuration];

3. UIImage imagenamed

(1) After the use of the picture, will not be released directly, the specific release time is determined by the system, suitable for small pictures, commonly used image processing

(2) If you want to release a quick release picture, you can use [UIImage Imagewithcontentsoffile:path] to instantiate the image

4. Methods to reconstruct the strategy

(1) Copy the code with commonality to a new method

(2) Increase the parameters of the method according to the different invocation conditions

Tip: Do not worry about refactoring when writing programs, sometimes the code first, it is easier to see how the refactoring will be better

5. The picture material in bundle (bundle)

When dragging footage into a project, you typically select

(1) Destination: tick

(2) Folders:

1) Select the first item: Yellow folder

Note: Xcode in the folder, all the bundle is in the same folder, therefore, cannot appear the file name of the case

Characteristics:

A. You can use [NSBundle Mainbundle] directly as a resource path, high efficiency!

B. You can load an image using [UIImage imagenamed:]

2) Select the second item: Blue folder

Note: Xcode sub-folders, bundles in the same folder, so you can appear the name of the file case

Characteristics:

A. Need to splice the actual path on the basis of [NSBundle mainbundle], inefficient

B. Cannot use [UIImage imagenamed:] Load diagram

iOS Development UI Chapter-ios three simple animation settings in development

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.