Turn from the top of the text to the Great God's blog: http://www.cnblogs.com/wendingding/p/3751519.html
iOS development UI, often with the need to add animation effects, here is a summary of the three ways to add animations:
First, finishing animation
// beginanimations indicates that subsequent code will "participate in" the animation [UIView beginanimations:nil context:nil]; // Set Animation duration [UIView setanimationduration:2.0]; = rect; // Commitanimations, commits and generates animations for all animations after beginanimation [UIView commitanimations];
Note: If you just modify the properties of the control, it is easier to use the end-of-line animation, but if you need to do subsequent processing after completion, it is not so convenient, this is to consider using block blocks of code.
Second, block code blocks animation
// a simple animation effect [UIView animatewithduration:2.0 animations:^{ showlab.alpha=0; } Completion:^(BOOL finished) { [Showlab Removefromsuperview]; }];
Note: 1, in the actual development is more commonly used block code block to handle animation operations
2, fast 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 ready-made footage, connect to Uiimageview and button buttons
code example:
-(ibaction) eat {Nsmutablearray*arraym=[Nsmutablearray array]; for(intI=0; i< +; i++) {[Arraym addobject:[uiimage imagenamed:[nsstring stringWithFormat:@"eat_%02d.jpg", I]]; } //set up an animated array[Self.tom Setanimationimages:arraym]; //set the number of animations to play[Self.tom Setanimationrepeatcount:1]; //Set animation playback time[Self.tom setanimationduration: +*0.075]; //Start Animation[Self.tom startanimating];}
Click the button to perform the animation
Iv. Supplementary Knowledge
1, Imagees. Material in the Xcassets
(1) Images supported in PNG format
(2) The image only supports [UIImage imagenamed] instantiation, but cannot be loaded from the button
(3) At compile time, Images. All files in the 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 images, commonly used image processing
(2) If you want to quickly release a picture, you can use [UIImage Imagewithcontentsoffile:path] to instantiate the image
4. Method Reconstruction Strategy
(1) Copy the code with commonality to a new method
(2) Increase the parameters of the method according to the different invocation conditions
Note: In writing the program is not anxious to refactor, sometimes it is written 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
Ways to add animations to iOS