The so-called animation group is the combination of some animation to the layer so that its animation more flexible. It is simple to assign an animated array to its Animations property.
[CPP]View Plaincopy
- -(void) Demoanimationgroup
- {
- Static NSString * Const KCAPOSTIONKEYPATH = @"position";
- Static NSString * Const KCAOPACITYKEYPATH = @"opacity";
- Static NSString * Const KCAROTATIONKEYPATH = @"transform.rotation";
- Static NSString * Const KCASCALEKEYPATH = @"Transform.scale";
- Uibezierpath *path = [Uibezierpath Bezierpath];
- [Path movetopoint:_demoview.layer.position];
- [Path Addcurvetopoint:cgpointmake (260) controlpoint1:cgpointmake (0, 460) controlpoint2:cgpointmake (320, 0)];
- //Path animation
- Cakeyframeanimation *posanimation = [Cakeyframeanimation Animationwithkeypath:kcapostionkeypath];
- Posanimation.path = path. Cgpath;
- Posanimation.timingfunction = [Camediatimingfunction functionwithname:kcamediatimingfunctioneaseineaseout];
- //Transparency Animation
- Cabasicanimation *opaanimation = [Cabasicanimation Animationwithkeypath:kcaopacitykeypath];
- Opaanimation.duration = 2.0f;
- Opaanimation.tovalue = @ (0.3f);
- opaanimation.autoreverses = YES;
- //Rotate animation
- Cabasicanimation *rotanimation = [Cabasicanimation Animationwithkeypath:kcarotationkeypath];
- Rotanimation.duration = 2.0f;
- Rotanimation.tovalue = @ (M_PI);
- rotanimation.autoreverses = YES;
- //Zoom animation
- Cabasicanimation *scaanmaiton = [Cabasicanimation Animationwithkeypath:kcascalekeypath];
- Scaanmaiton.duration = 2.0f;
- Scaanmaiton.tovalue = @ (1.5f);
- scaanmaiton.autoreverses = YES;
- //Set animation group
- Caanimationgroup *group = [Caanimationgroup animation];
- Group.animations = @[posanimation, Opaanimation, Rotanimation, Scaanmaiton];
- Group.duration = 4.0f;
- Group.removedoncompletion = NO;
- Group.fillmode = Kcafillmodeforwards;
- [_demoview.layer Addanimation:group Forkey:nil];
- }
This animation group adds some simultaneous animations to the layer of the demoview, such as the Bezier path of the double-control point, fade-out of transparency, rotation, and scaling. Catransition transition animations can be found in almost all apps, often for switching between view controllers or for single-view controller page transitions, or for adding animations to custom Uistoryboardsegue. It is also a subclass of Caanimation, which gives the layer an animated effect of moving out of the screen and moving in. Its common properties are subtypes of type transition type subtype transition type, where there are many transition types, initially four versions, and later added, in string format. The first four: Fade,push,movein,reveal later added the effect is more rich and dazzling, there are cube, Oglflip, Suckeffect, Rippleeffect, Pagecurl, Pageuncurl, Camerairishollowopen, Camerairishollowclose.
[CPP]View Plaincopy
- -(void) viewtransition
- {
- Static NSString * Const KCATRANSITIONTYPEFLIP = @"Oglflip"; //page Turn effect
- Catransition *transition = [catransition animation];
- Transition.type = Kcatransitiontypeflip;
- Transition.subtype = Kcatransitionfromright;
- Transition.duration = 1.5f;
- [_transitionorangeview.layer addanimation:transition Forkey:nil];
- [Self.view performselector: @selector (sendsubviewtoback:) Withobject:_transitionorangeview afterdelay:1.0f];
- }
This method is simple to achieve the effect of the view page, of course, the current controller root view only a subview, so the use of Sendsubviewtoback method after the display is still the view, but see the animation effect. Now the UIView transition animation has a more convenient class method + transitionwithview:duration:options:animations:completion:+ Transitonfromview:toview: Duration:options:completion: These two method parameters add Apple's recommended block code, also let the transition animation in a method of processing, also to the end of the animation processing, more convenient to use.
[CPP]View Plaincopy
- -(void) anothertransition
- {
- _transitionblueview = [[UIView alloc] initWithFrame:self.view.bounds];
- _transitionblueview.backgroundcolor = [Uicolor Bluecolor];
- [UIView Transitionfromview:_transitionorangeview
- Toview:_transitionblueview
- duration:1.0f
- Options:uiviewanimationoptiontransitioncrossdissolve
- Completion:nil];
- }
The code is simple and easy to read. One thing to note, though, is that there are not many parameters here, and I did not load the blue view through Addsubview into Self.view, nor did the Orange view Removefromsuperview, which are encapsulated implicitly in this class method. Demo sample Click to open link
iOS development UI chapter-core animations (transition animations and group animations)