iOS development UI chapter-core animations (transition animations and group animations)

Source: Internet
Author: User

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
  1. -(void) Demoanimationgroup
  2. {
  3. Static NSString * Const KCAPOSTIONKEYPATH = @"position";
  4. Static NSString * Const KCAOPACITYKEYPATH = @"opacity";
  5. Static NSString * Const KCAROTATIONKEYPATH = @"transform.rotation";
  6. Static NSString * Const KCASCALEKEYPATH = @"Transform.scale";
  7. Uibezierpath *path = [Uibezierpath Bezierpath];
  8. [Path movetopoint:_demoview.layer.position];
  9. [Path Addcurvetopoint:cgpointmake (260) controlpoint1:cgpointmake (0, 460) controlpoint2:cgpointmake (320, 0)];
  10. //Path animation
  11. Cakeyframeanimation *posanimation = [Cakeyframeanimation Animationwithkeypath:kcapostionkeypath];
  12. Posanimation.path = path. Cgpath;
  13. Posanimation.timingfunction = [Camediatimingfunction functionwithname:kcamediatimingfunctioneaseineaseout];
  14. //Transparency Animation
  15. Cabasicanimation *opaanimation = [Cabasicanimation Animationwithkeypath:kcaopacitykeypath];
  16. Opaanimation.duration = 2.0f;
  17. Opaanimation.tovalue = @ (0.3f);
  18. opaanimation.autoreverses = YES;
  19. //Rotate animation
  20. Cabasicanimation *rotanimation = [Cabasicanimation Animationwithkeypath:kcarotationkeypath];
  21. Rotanimation.duration = 2.0f;
  22. Rotanimation.tovalue = @ (M_PI);
  23. rotanimation.autoreverses = YES;
  24. //Zoom animation
  25. Cabasicanimation *scaanmaiton = [Cabasicanimation Animationwithkeypath:kcascalekeypath];
  26. Scaanmaiton.duration = 2.0f;
  27. Scaanmaiton.tovalue = @ (1.5f);
  28. scaanmaiton.autoreverses = YES;
  29. //Set animation group
  30. Caanimationgroup *group = [Caanimationgroup animation];
  31. Group.animations = @[posanimation, Opaanimation, Rotanimation, Scaanmaiton];
  32. Group.duration = 4.0f;
  33. Group.removedoncompletion = NO;
  34. Group.fillmode = Kcafillmodeforwards;
  35. [_demoview.layer Addanimation:group Forkey:nil];
  36. }

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
  1. -(void) viewtransition
  2. {
  3. Static NSString * Const KCATRANSITIONTYPEFLIP = @"Oglflip"; //page Turn effect
  4. Catransition *transition = [catransition animation];
  5. Transition.type = Kcatransitiontypeflip;
  6. Transition.subtype = Kcatransitionfromright;
  7. Transition.duration = 1.5f;
  8. [_transitionorangeview.layer addanimation:transition Forkey:nil];
  9. [Self.view performselector: @selector (sendsubviewtoback:) Withobject:_transitionorangeview afterdelay:1.0f];
  10. }

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
  1. -(void) anothertransition
  2. {
  3. _transitionblueview = [[UIView alloc] initWithFrame:self.view.bounds];
  4. _transitionblueview.backgroundcolor = [Uicolor Bluecolor];
  5. [UIView Transitionfromview:_transitionorangeview
  6. Toview:_transitionblueview
  7. duration:1.0f
  8. Options:uiviewanimationoptiontransitioncrossdissolve
  9. Completion:nil];
  10. }

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)

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.