iOS Development coreanimation

Source: Internet
Author: User
Tags set time

The Core animation is directly acting on the Calayer (not UIView) very powerful animations across Mac OS X and iOS platforms Api,core Animation animation execution is done in the background and does not block the main thread. Core animation inheritance structure
Core animation inheritance Structure Note: Virtual classes in core animations cannot be used, but should use real classes in their subclasses. steps to use Core animation

If the previous version is Xcode6, import the <QuartzCore/QuartzCore.h> framework (there is no coreanimation framework) Development steps:

First you have to have Calayer(because Coreanimation is acting on Calayer)

Initializes a Caanimation object and sets some animation-related properties

By calling Calayer's Addanimation:forkey: Method, add Caanimation object to Calayer so that you can start the animation

By calling the Calayer Removeanimationforkey: method, you can stop some of the properties in the animation caanimation in Calayer :

Duration: Duration of animation

RepeatCount: Repeat times, infinite loops can be set huge_valf or maxfloat

RepeatDuration: Repeat Time

Removedoncompletion: The default is yesto remove the animation from the layer after it is finished, and the graphic will revert to the state before the animation was executed. If you want the layer to remain in the state after the animation has been performed, set to No, but * also set Fillmode to kcafillmodeforwards*

BeginTime: Can be used to set the animation delay execution time, if you want to delay 2s, set to Cacurrentmediatime () +2,cacurrentmediatime () for the current time of the layer

Timingfunction: Speed control function, control the rhythm of animation operation

Delegate: Animation agent

Fillmode determines the behavior of the current object in a non-active time period. (In order to fillmode effective, it is best to set removedoncompletion = NO)

Kcafillmoderemoved This is the default value, that is, when the animation before and after the end of animation, the animation has no effect on the layer, after the animation, layer will revert to the previous state

Kcafillmodeforwards when the animation is over, layer will keep the final state of the animation.
Kcafillmodebackwards before the animation starts, just add the animation to a layer,layer and immediately enter the initial state of the animation and wait for the animation to begin.

Kcafillmodeboth This is actually the synthesis of the top two. Before the animation is joined, the layer is in the initial state of animation, and layer remains the final state of animation after the animation is finished.

Camediatimingfunction: Speed control function

Kcamediatimingfunctionlinear (linear): uniform, give you a relatively static feeling

Kcamediatimingfunctioneasein (Progressive): Animation slowly enter, and then accelerate the departure

Kcamediatimingfunctioneaseout (Fade Out): The animation enters at full speed, then slows down to reach the destination

Kcamediatimingfunctioneaseineaseout (Progressive): animation slowly into the middle of the acceleration, and then slowed to reach the destination. This is the default animation behavior. Caanimation Proxy Method

Caanimation defines the proxy method in the taxonomy. is to add the classification to NSObject, so any object, become caanimation agent, all can.

When the animation starts, it calls

-(void) Animationdidstart: (caanimation *) Anim;

Call when the animation stops

-(void) Animationdidstop: (Caanimation *) Anim finished: (BOOL) flag; pauses and restores of animations on Calayer

Time out

  -(void) Pauselayer: (calayer*) layer
  {
     cftimeinterval pausedtime = [Layer Converttime:cacurrentmediatime () Fromlayer:nil];

     Let the calayer time stop walking
     layer.speed = 0.0;
     Let Calayer time stay at Pausedtime this moment
     layer.timeoffset = pausedtime;
  }

Recovery

  -(void) Resumelayer: (calayer*) layer
  {
      cftimeinterval pausedtime = layer.timeoffset;
      1. Let the calayer time continue to walk
        layer.speed = 1.0;
      2. Cancels the last recorded stay time
        layer.timeoffset = 0.0;
      3. Cancels the last set time
        layer.begintime = 0.0;    
      4. Calculates the time of the pause (you can also use Cacurrentmediatime ()-pausedtime)
      cftimeinterval timesincepause = [Layer converttime: Cacurrentmediatime () Fromlayer:nil]-pausedtime;
      5. Sets the start time relative to the parent coordinate system (backward timesincepause)
        layer.begintime = Timesincepause;
  }
cabasicanimation--Basic Animation

Basic animation, a subclass of Capropertyanimation

Attribute Description:

KeyPath: Name of the property to be changed (pass string)

Fromvalue:keypath the corresponding property's initial value

Tovalue:keypath the end value of the corresponding property

Animation Process Description:

As the animation progresses, the value of the corresponding property keypath gradually from Fromvalue to tovalue in the duration of duration length.

KeyPath content is an Calayer animatable property of an animation

If the fillmode=kcafillmodeforwards is removedoncomletion=no at the same time , after the animation finishes, the layer remains displayed after the animation has been performed. but in essence, the property value of the layer is the initial value of the animation before it is executed, and it is not really changed. cakeyframeanimation--key frame animation

Key-frame animations, which are also capropertyanimation subclasses, differ from Cabasicanimation:
Cabasicanimation can only be changed from one numeric value (Fromvalue) to another (Tovalue), and Cakeyframeanimation saves the values using a Nsarray

Attribute Description: Values: The above Nsarray object. The elements inside are called "keyframes" (keyframe). The animated object displays each keyframe path in the values array in the specified time (duration): You can set up a cgpathref, cgmutablepathref, and let the layer move according to the path trajectory. Path only works on the anchorpoint and position of Calayer. If path is set, values are ignored Keytimes: You can specify a corresponding point in time for the corresponding keyframe, and each time value ranging from 0 to 1.0,keytimes corresponds to each frame of values. If Keytimes is not set, the time of each keyframe is divided equally

Cabasicanimation can be viewed as a cakeyframeanimation with only 2 keyframes. caanimationgroup--Animation Group

Animation group, is a subclass of Caanimation, you can save a group of animated objects, the Caanimationgroup object after adding layers, all animation objects in the group can concurrently run

Attribute Description: Animations: A nsarray that is used to hold a set of animated objects

by default, a set of animated objects is run at the same time, or you can change the start time of the animation by setting the BeginTime property of the animation object Transitions Animation--catransition

Catransition is a subclass of caanimation that is used to animate transitions, providing layers with animations to move out of the screen and move into the screen. iOS has less effect than Mac OS x transitions
Uinavigationcontroller is the animation effect of pushing the controller's view into the screen through Catransition

Animation properties: Type: Animation transition type subtype: Animation transition Direction startprogress: Animation Start point (percentage of overall animation) Endprogress: Animation endpoint (percentage of overall animation) 1. Single View

+ (void) Transitionwithview: (UIView *) View Duration: (nstimeinterval) Duration options: (uiviewanimationoptions) Options animations: (void (^) (void)) animations completion: (void (^) (BOOL finished) completion; Parameter description: Duration: Animation duration View: View options for Transitions Animation: type of transition animation animations: The code that changes the view properties is placed in this block completion: After the animation, will automatically call this block 2. Dual View

+ (void) Transitionfromview: (UIView *) Fromview Toview: (UIView *) Toview Duration: (nstimeinterval) Duration options: ( uiviewanimationoptions) Options Completion: (void (^) (BOOL finished)) completion; Parameter description: Duration: Animation duration options: The type of transition animation animations: The code that changes the view properties is placed in this block completion: This block is automatically invoked when the animation is finished3. Write your own transitionsCreate a transition animation: [catransition Animation] Set animation property values to add to layers that need to be animated [layer Addanimation:animation Forkey:nil]type of transitions animation (NSString *type) fade: Cross-fade transition Push: New view launches old view Movein: Move new view above old view reveal: Move the old view away, showing the new view below Cube : Cube Rollover effect oglflip: Flip effect from top to bottom suckeffect: Shrinkage effect, as a piece of cloth is drawn away rippleeffect: Drip effect pagecurl: Page Up effect pageuncurl: Page Down effect camerairishollowopen: Camera lens Open Effect Camerairishollowclos: Camera lens closure Effect direction of Transitions Animation (NSString *subtype) start in a certain direction: Fromleft, Fromrigh

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.