Text top-top iOS Development UI Chapter-ios development three simple animation settings

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:

    beginanimations that the code thereafter "participates in" the animation     [UIView beginanimations:nil context:nil];  Set Animation duration    [UIView setanimationduration:2.0]; self.headImageView.bounds =//  Commitanimations, commits and generates animations for all animations after beginanimation [UIView commitanimations];       

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:

   simple animation effect    [UIView animatewithduration:2.0 animations:^{        showlab.alpha=0;} completion: ^(BOOL finished) {[Showlab removefromsuperview];}];     

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:

-(ibaction) Eat {Nsmutablearray *arraym=[Nsmutablearray array];for (int i=0; i<40; i++) {[Arraym addobject:[uiimage imagenamed:[nsstring stringWithFormat:@ "eat_%02d.jpg", I]];} // Set animation array [Self.tom Setanimationimages:arraym]; // set animation play times [Self.tom setanimationrepeatcount:1]; // Set animation playback time [Self.tom setanimationduration:40*0.075]; // start animation [Self.tom startanimating];}            

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:nil afterDelay: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

Text top-top iOS Development UI Chapter-ios development three simple animation settings

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.