Group animations in Core animation

Source: Internet
Author: User

The motion of an object in actual development is often a compound motion, but the motion of a single attribute is less, but the property animation can only animate one property at a time (whether it is the underlying animation or the Keyframe animation). This way, to make a composite motion animation, you must create multiple property animations to combine. The combination of one or two animations may be easier to deal with, but the combination of more animations can often become cumbersome, and animation groups are produced based on such a situation. Animation Group is a series of animation, all the animation added to the animation group is controlled by the animation group, so that all kinds of animation common behavior can be unified control without having to set up separately, and put in animation group animation can be executed concurrently, together to build a complex animation effect.

Animation groups are not complex to use, first creating individual animations (either Basic or keyframe), then adding the underlying animation to the animation group, and finally adding the animation group to the layer.

////VIEWCONTROLLER.M//Demo02183////Created by Wiseman on 16/2/18.//Copyright (c) 2016 Wiseman. All rights reserved.//#import "ViewController.h"@interfaceViewcontroller () {Calayer*_layer;}@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib. //Customizing a layer_layer=[[Calayer alloc]init]; _layer.bounds=cgrectmake (0,0,Ten, -); _layer.position=cgpointmake ( -, Max); _layer.backgroundcolor=[Uicolor Redcolor].    Cgcolor;    [Self.view.layer Addsublayer:_layer]; }-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *)Event{[self groupanimation];}#pragmaMark-Group Animation-(void) groupanimation{//1. Create an animation groupCaanimationgroup *animationgroup=[Caanimationgroup animation]; //2. Setting animations and other properties in a groupCabasicanimation *basicanimation=[self rotationanimation]; Cakeyframeanimation*keyframeanimation=[self translationanimation]; Animationgroup.animations=@[basicanimation,keyframeanimation]; Animationgroup.Delegate=Self ; Animationgroup.duration=10.0;//Sets the animation time, which is no longer valid if the animation has been set in animation group animation propertiesAnimationgroup.begintime=cacurrentmediatime ();//Five seconds delay execution//3. Animating a layer[_layer addanimation:animationgroup forkey:nil];}#pragmaMark-Basic Rotation Animation-(Cabasicanimation *) rotationanimation{//1. Create a basic animationCabasicanimation *basicanima = [cabasicanimation animationwithkeypath:@"transform.rotation.z"]; //2.CGFloat tovalue = m_pi_2 *3; Basicanima.tovalue=[NSNumber Numberwithfloat:tovalue]; Basicanima.autoreverses=true; Basicanima.repeatcount=huge_valf; Basicanima.removedoncompletion=YES; returnBasicanima;}#pragmaMark-keyframe Move Animation-(Cakeyframeanimation *) translationanimation{cakeyframeanimation*keyframeanima = [Cakeyframeanimation animationwithkeypath:@"position"]; Uibezierpath*bezierpath =[Uibezierpath Bezierpath]; [Bezierpath Movetopoint:cgpointmake ( -, -)]; [Bezierpath Addcurvetopoint:cgpointmake ( -, -) Controlpoint1:cgpointmake (0, -) Controlpoint2:cgpointmake ( $, -)]; Keyframeanima.path=Bezierpath.cgpath; returnKeyframeanima;}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}@end

Group animations in Core animation

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.