<span id="Label3"></p><p><p>Cabasicanimation Basic Animation</p></p><pre class="brush:objc;gutter:true;"><pre class="brush:objc;gutter:true;">#define Radin (angle) (m_pi* (angle)/180)//define the radian you need<br>@interface viewcontroller () @property (nonatomic,strong) calayer *layer; @property (strong, nonatomic) iboutlet UIView * readview; @property (strong, nonatomic) iboutlet uiimageview *iconview;-(ibaction) begin: (id) sender;-(ibaction) stop: ( Id) sender;</pre></pre><p><p></p></p><p><p>Create Calayer</p></p><pre class="brush:objc;gutter:true;"><pre class="brush:objc;gutter:true;">Calayer *layer =[calayer layer]; Layer.position=cgpointmake (+); Layer.bounds=cgrectmake (0, 0,.); Layer.backgroundcolor =[uicolor redcolor]. cgcolor; [self.view.layer addsublayer:layer]; self.layer=layer;</pre></pre><p><p>Cabasicanimation</p></p><p><p>Rotating</p></p><pre class="brush:objc;gutter:true;"><pre class="brush:objc;gutter:true;">1. Create an Animated object cabasicanimation *anim =[cabasicanimation animation]; 2. Set the animation object //keypath determines how to perform the animation, adjust that property to perform animation [email protected] "transform"; anim.tovalue=[nsvalue valuewithcatransform3d:catransform3dmakerotation (m_pi_4, 1,-1, 0)]; The time anim.duration=2.0 of the animation execution ; /** RID layer to keep the animation after the completion of the state **/ //animation after the completion of the animation do not delete the anim.removedoncompletion=no; Keep up-to-date status anim.fillmode= kcafillmodeforwards; 3. Add animation [self.layer Addanimation:anim forkey:nil];</pre></pre><p><p>Scaling</p></p><pre class="brush:objc;gutter:true;"><pre class="brush:objc;gutter:true;">1. Create an Animated object cabasicanimation *anim =[cabasicanimation animation]; 2. Set the animation object //keypath determines how to perform the animation, adjust that property to perform animation [email protected] "bounds"; Anim.tovalue=[nsvalue valuewithcgrect:cgrectmake (0, 0, $)]; The time anim.duration=2.0 of the animation execution ; /** RID layer to keep the animation after the completion of the state **/ //animation after the completion of the animation do not delete the anim.removedoncompletion=no; Keep up-to-date status anim.fillmode= kcafillmodeforwards; 3. Add animation [self.layer Addanimation:anim forkey:nil];</pre></pre><p><p>Translation</p></p><pre class="brush:objc;gutter:true;"><pre class="brush:objc;gutter:true;"> 1. Create an Animated object cabasicanimation *anim =[cabasicanimation animation]; 2. Set the animation object //keypath determines how to perform the animation, adjust that property to perform animation [email protected] "position"; Anim.fromvalue=[nsvalue valuewithcgpoint:cgpointmake (0, 0)]; Anim.tovalue=[nsvalue Valuewithcgpoint:cgpointmake ($)]; The time anim.duration=2.0 of the animation execution ; /** RID layer to keep the animation after the completion of the state **/ //animation after the completion of the animation do not delete the anim.removedoncompletion=no; Keep up-to-date status anim.fillmode= kcafillmodeforwards; 3. Add animation [self.layer Addanimation:anim forkey:nil];</pre></pre><p><p>Cakeyframeanimation: Keyframe Animation</p></p><p><p>Translation</p></p><pre class="brush:objc;gutter:true;"> The first way cakeyframeanimation * anim=[cakeyframeanimation animation]; Anim.keypath [email protected] "position"; Nsvalue * V1 =[nsvalue valuewithcgpoint:cgpointzero]; Nsvalue * V2 =[nsvalue valuewithcgpoint:cgpointmake (100, 0)]; Nsvalue * V3 =[nsvalue valuewithcgpoint:cgpointmake (100, 200)]; Nsvalue * V4 =[nsvalue valuewithcgpoint:cgpointmake (300, 200)]; [email protected] [v1,v2,v3,v4]; anim.duration=2.0; anim.removedoncompletion=no; anim.fillmode=kcafillmodeforwards; [self.readView.layer Addanimation:anim forkey:nil]; The second way cakeyframeanimation * anim1=[cakeyframeanimation animation]; Anim1.keypath [email protected] "position"; anim1.duration=2.0; anim1.removedoncompletion=no; anim1.fillmode=kcafillmodeforwards; Create path Cgmutablepathref path=cgpathcreatemutable (); Add a circle Cgpathaddellipseinrect to the path (path, NULL, cgrectmake (100, 100, 200, 200)); Anim.path= path;Release Cgpathrelease (path); Set the execution rhythm of the animation (constant speed, Fast and slow, etc.)//kcamediatimingfunctioneaseout: at first, it will be slower, the middle is accelerating, and it will slow down when it is near the end anim.timingfunction=[ Camediatimingfunction functionwithname:kcamediatimingfunctioneaseout]; After the listening animation there will be two proxy methods anim.delegate=self; [self.readView.layer addanimation:anim1 forkey:nil];</pre><pre class="brush:objc;gutter:true;"><pre class="brush:objc;gutter:true;">#pragma mark-animation Agent method #pragma the Mark animation starts with the Call-(void) animationdidstart: (caanimation *) anim{ } #pragma mark animation ends when the call-( Void) animationdidstop: (caanimation *) anim finished: (BOOL) flag{ }</pre></pre><p><p></p></p><p><p>Jitter</p></p><pre class="brush:objc;gutter:true;"><pre class="brush:objc;gutter:true;">Start Jitter-(ibaction) begin: (id) sender { //create cakeyframeanimation *anim =[cakeyframeanimation animation]; Anim.keypath [email protected] "transform.rotation"; A[email protected][@ (-radin (4)), @ (radin (4)), @ (-radin (4))]; anim.duration=0.15; Number of repetitions anim.repeatcount=maxfloat; anim.removedoncompletion=no; Anim.fillmode =kcafillmodeforwards; [self.iconView.layer Addanimation:anim forkey:@ "shake"]; } Stop Jitter-(ibaction) stop: (id) sender { [self.iconView.layer removeanimationforkey:@ "shake"]; }</pre></pre><p><p></p></p><p><p>IOS coreanimation (core Animation)</p></p></span>
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