iOS Promotion path-animation cabaseanimation

Source: Internet
Author: User

Want to implement animation in the Calayer is very easy, beginners may be limited to the uiview level of thought, in fact, do not put calayer will be easier than you think and clear thinking, the previous essay on some of the Calayer properties, if you change some properties such as bounds, Position you'll find that it comes with an implicit animation and works well, but here you can't customize animation events and have a set of animations execute effectively. If you want to achieve the above results, you need to cabaseanimation

   //Show AnimationsCabasicanimation * contentanimation = [cabasicanimation animationwithkeypath:@"Contents"]; Contentanimation.fromvalue=self.imageLayer.contents; Contentanimation.tovalue=(__bridge ID) (image2.    Cgimage); Contentanimation.duration=1.0f; //Bounds AnimationCabasicanimation * boundsanimation = [cabasicanimation animationwithkeypath:@"bounds"]; Boundsanimation.fromvalue=[Nsvalue valueWithCGRect:self.imageLayer.bounds]; Boundsanimation.tovalue= [Nsvalue Valuewithcgrect:cgrectmake (0,0,1,1)]; Boundsanimation.duration=1.0f; //Combo AnimationsCaanimationgroup * GROUNP =[Caanimationgroup animation]; Grounp.animations=@[contentanimation,boundsanimation]; Grounp.duration=1.0f; //set the value after the end of the layer animationSelf.imageLayer.bounds = CGRectMake (0,0,1,1); Self.imageLayer.contents=(__bridge ID) (image2.    Cgimage); [Self.imagelayer ADDANIMATION:GROUNP Forkey:nil];

As the above code is a combination of animation, including the transformation of the image and layer bounds changes, when creating animation to write the name of the property you want to change, this must not be written wrong, Fromvalue need to write the initial state of the property, Tovalue need to write the property changes after the value of the input values are objects, the last animation will not really change the property value of the layer, if not processed after the animation will be back to the original state, want to retain the original state to be the last assignment.

iOS Promotion path-animation cabaseanimation

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.