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 indicates that subsequent code will "participate in" the animation [UIView beginanimations:nil context:nil];//Set the duration of the animation [UIView SETANIMATIONDURATION:2.0]; Self.headImageView.bounds = 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 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 the number of animation plays [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: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