In iOS, there are two kinds of animation, one is the animation method of operation UIView, the other is the core animation, but in IOS7, UIView is involved with the core animation.
Mode one (animating with the core animation)
Catransition *animation = [catransition animation]; @" reveal " ; 1 ; = kcatransitionreveal; [Self.myView.layer addanimation:animation Forkey:nil]; = Self.myView.center; Max ; [Self.myview Setcenter:point];
Basic animation (cabasicanimation), is a subclass of Capropertyanimation, an animation can control the change of a property, the change value can only be two values, can be set in Fromvalue and Tovalue two values
Cabasicanimation *baseanimation = [cabasicanimation animationwithkeypath:@"bounds"]; Baseanimation.fromvalue= [Nsvalue Valuewithcgrect:cgrectmake ( -, -, -, -)]; Baseanimation.tovalue= [Nsvalue Valuewithcgrect:cgrectmake ( -, -, $, $)]; Baseanimation.duration=2.0; Baseanimation.removedoncompletion=NO; Baseanimation.fillmode=kcafillmodeforwards; Baseanimation.repeatcount=maxfloat; [Self.myView.layer addanimation:baseanimation Forkey:nil];
Frame animation (cakeyframeanimation), frame animation is also a subclass of Capropertyanimation, so it is also the control of a view of the properties of animation, unlike Cabaseanimation, Cakeyframeanimation can add multiple keyframes, and cabaseanimation can be seen as a frame animation of two keyframes, and we can take advantage of frame animation keyframes to make more interesting animations, such as bubble effects.
Caanimationgroup *group =[[Caanimationgroup alloc] init];//DisplacementCakeyframeanimation *positionanima = [cakeyframeanimation animationwithkeypath:@"position"]; Positionanima.calculationmode=kcaanimationcubicpaced; Positionanima.duration= 5; Positionanima.fillmode=kcafillmodeforwards; Positionanima.removedoncompletion=NO; Positionanima.repeatcount=maxfloat; Positionanima.timingfunction=[Camediatimingfunction functionwithname:kcamediatimingfunctionlinear];//Add a move pathCgmutablepathref Curvedpath =cgpathcreatemutable (); CGRect Circlecontainer= Cgrectinset (Myview.frame, MyView.frame.size.width/2-3, MyView.frame.size.height/2-3); Cgpathaddellipseinrect (Curvedpath, NULL, Circlecontainer); Positionanima.path=Curvedpath; Cgpathrelease (Curvedpath); [Myview.layer Addanimation:positionanima Forkey:nil];//Zoom xCakeyframeanimation *scalex = [cakeyframeanimation animationwithkeypath:@"transform.scale.x"]; Scalex.duration=1.0; Scalex.values= @[@1.0,@1.1,@1.0]; Scalex.keytimes= @[@0.0,@0.5,@1.0]; Scalex.repeatcount=maxfloat; Scalex.autoreverses=YES; Scalex.timingfunction=[Camediatimingfunction functionwithname:kcamediatimingfunctioneaseout]; [Myview.layer Addanimation:scalex Forkey:nil];//Zoom yCakeyframeanimation *scaley = [cakeyframeanimation animationwithkeypath:@"Transform.scale.y"]; Scaley.duration=1.5; Scaley.values= @[@1.0,@1.1,@1.0]; Scaley.keytimes= @[@0.0,@0.5,@1.0]; Scaley.repeatcount=maxfloat; Scaley.autoreverses=YES; Group.animations=@[positionanima,scalex,scaley]; Scaley.timingfunction=[Camediatimingfunction functionwithname:kcamediatimingfunctioneaseout]; [Myview.layer Addanimation:scaley Forkey:nil];
Run effect
Because my computer is a black apple, so will be a bit, haha, white Apple should not be like this.
- Animation Group (Caanimationgroup) Caanimation subclass, you can save a set of animated objects, say Caanimationgroup object after the join layer, all the animation in the group can run simultaneously, so when we need to do more than the animation and execution time is different , the animation group is not applicable. For example, the bubble effect above.
Group.animations = [animate object inside];
Mode two (add animation with UIView)
- UIView Animation (hand code)
[UIView Beginanimations:nil context:nil]; [UIView setanimationduration: 4]; = Self.myView.center; Max ; [Self.myview Setcenter:point]; [UIView commitanimations]; [UIView Beginanimations:nil Context:nil]; [UIView setanimationduration: 4 ]; [Self.myview Setalpha: 0.1 ]; [UIView commitanimations];
[UIView animatewithduration:4 animations:^{ = self.myView.center; Max ; [Self.myview setcenter:point]; }];
- UIView Animation (block frame animation), opened from IOS7, Apple provides a more convenient way to invoke frame animation, without creating a new frame animation instance, directly control the properties of the layer.
[uiview animatekeyframeswithduration:0.5 delay:1 options:uiviewkeyframeanimationoptionautoreverse animations: ^{self.view.bounds = CGRectMake (30 ,
30
, 30 , 30 ); } Completion: ^
- UIView transitions Animation.
+ (void) Transitionfromview: (UIView *) Fromview Toview: (UIView *) Toview Duration: (nstimeinterval) duration Options: (uiviewanimationoptions) Options completion: (void (^) (BOOL finished)) completion
This method should not be easy to understand, simply put, after this method is called, the equivalent of executing two lines of code,
// Add Toview to Parent view [Fromview.superview Addsubview:toview]; // Remove the Fromview from the parent view [Fromview.superview Removefromsuperview]; - Duration: Duration of animation - Duration: Duration of animation - options: Type of transition animation - Animations: Place code that alters the view properties in this block -completion: The block is automatically called when the animation is finished
iOS Animation Implementation Summary