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