CoreAnimation application and usage of iPhone applications

Source: Internet
Author: User

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:

 
 
  1. @property CGRect bounds;   
  2. @property CGPoint position;   
  3. @property CATransform3D transform; 

How to transfer images?

 
 
  1. - (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.

 
 
  1. @property(retain) CAMediaTimingFunction *timingFunction; timingFunction 

Is a CAMediaTimingFunction object, which is generally created as follows:

 
 
  1. [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];  
  2.  kCAMediaTimingFunctionEaseIn 

Can be replaced with the following value

 
 
  1. :NSString * const kCAMediaTimingFunctionLinear;  
  2.  NSString * const kCAMediaTimingFunctionEaseIn;  
  3.  NSString * const kCAMediaTimingFunctionEaseOut;  
  4.  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.

 
 
  1. CABasicAnimation *ani = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];  
  2.  ani.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];  
  3.  ani.fromValue = [UIColor blueColor].CGColor;  
  4.  ani.toValue = [UIColor clearColor].CGColor;  
  5. ani.duration = 3;   
  6. [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.

 
 
  1. + (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.

 
 
  1. :@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.

 
 
  1. CAKeyframeAnimation *ani = [CAKeyframeAnimation animationWithKeyPath:@"position"];   
  2. ani.values = [NSArray arrayWithObjects:  
  3. NSValue valueWithCGPoint:CGPointMake(100,200)],   
  4. [NSValue valueWithCGPoint:CGPointMake(200,200)],  
  5.  [NSValue valueWithCGPoint:CGPointMake(200,300)], nil];  
  6. 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.

 
 
  1. [UIView beginAnimations: nil context: nil];
  2. [UIView setAnimationDuration: 0.3];
  3. // View operations
  4. View. frame = xxx; [UIView commitAnimations];

Summary:IPhoneApplicationCoreAnimationI hope this article will help you with the introduction of applications and usage methods!

Related Article

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.