IPhoneApplicationCoreAnimationThe application and usage are described in this article,CoreAnimationIs Apple's user interfaceAnimation. Its framework is QuartzCore. framework. The project that needs to be added to this database during use. Let's take a look at the detailed description.
1. The vast majority of CALayerCALayer attributes are supported.Animation,Directly setting these values will implicitly call the animation effect, but the animation duration is short and almost invisible. To achieve an obvious animation effect, you need to call the animation explicitly.
Common attributes:
- @property CGRect bounds;
- @property CGPoint position;
- @property CATransform3D transform;
How to transfer images?
- - (void)addAnimation:(CAAnimation *)anim forKey:(NSString *)key
Anim is an animation object created by itself and inherits from CAAnimation. The key is the animation key, generally nil, or a set value, which is of little significance.
2. CAAnimationCAAnimation is the base class of all animation classes and is generally not used directly. It provides a very useful property for all subclasses.
- @property(retain) CAMediaTimingFunction *timingFunction; timingFunction
Is a CAMediaTimingFunction object, which is generally created as follows:
- [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
- kCAMediaTimingFunctionEaseIn
Can be replaced with the following value
- :NSString * const kCAMediaTimingFunctionLinear;
- NSString * const kCAMediaTimingFunctionEaseIn;
- NSString * const kCAMediaTimingFunctionEaseOut;
- NSString * const kCAMediaTimingFunctionEaseInEaseOut;
3. CABaseAnimation basic animations act directly on the attributes of CALayer objects. The following shows an animation that changes a layer from blue to transparent.
- CABasicAnimation *ani = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];
- ani.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
- ani.fromValue = [UIColor blueColor].CGColor;
- ani.toValue = [UIColor clearColor].CGColor;
- ani.duration = 3;
- [view1.layer addAnimation:ani forKey:@"ani1"];
Specifies the attributes to be animated. For example, you must change the backgroundColor attribute of the layer in the previous example.
- + (id)animationWithKeyPath:(NSString *)path;
Path specifies the attribute path to be changed, such as @ "bounds" and @ "bounds. size. width.
You only need to provide one or two of these three attributes.
- :@property(retain) id fromValue, toValue, byValue;
If fromValue and toValue exist, the animation changes from fromValue to toValue.
If fromValue and byValue exist, the animation changes from fromValue to fromValue + byValue.
If there is only toValue, the animation changes from the current value to toValue. If only byValue exists, the animation changes from the current value to the current value + byValue.
As you can imagine, when an animation is added to the CALayer object, the system starts a timer to refresh the attribute value of the layer, the value is calculated by fromValue and toValue based on a certain interpolation algorithm. Just imagine that the properties of the layer are not changed during the animation process. These display effects are completed by the GPU and do not change the attribute values of the layer. If necessary, you must set the attributes of the layer.
4. CAKeyframeAnimation Key Frame Animation sometimes you may need an animation in a non-fixed direction. For example, let a layer first move 100 pixels to the right and then move 100 pixels down. In this case, you can use the key frame animation.
- CAKeyframeAnimation *ani = [CAKeyframeAnimation animationWithKeyPath:@"position"];
- ani.values = [NSArray arrayWithObjects:
- NSValue valueWithCGPoint:CGPointMake(100,200)],
- [NSValue valueWithCGPoint:CGPointMake(200,200)],
- [NSValue valueWithCGPoint:CGPointMake(200,300)], nil];
- ani.duration = 3; [view1.layer addAnimation:ani forKey:@"ani2"];
6. UIView animations support UIView, which can directly support view animations and affect multiple views.
AnimationIt changes linearly. By default, the animation starts to slow down, and the animation starts to change faster and faster. The animation slows down and gets slower and slower. The animation starts to slow down and then gets slower and slower.
- [UIView beginAnimations: nil context: nil];
- [UIView setAnimationDuration: 0.3];
- // View operations
- View. frame = xxx; [UIView commitAnimations];
Summary:IPhoneApplicationCoreAnimationI hope this article will help you with the introduction of applications and usage methods!