Resizing and moving a UIView using Core Animation (CAKeyFrameAnimation)

Is it possible? I can change the opacity and position (in the center) of the layer, but whenever I try to change the size or origin, it does not work.

CAAnimationGroup* anigroup = [CAAnimationGroup new]; CGMutablePathRef thePath = CGPathCreateMutable(); CGPathAddRect(thePath, NULL, CGRectMake(0,0, 320, 480)); CGPathAddRect(thePath, NULL, CGRectMake(location.x - 16,location.y-24, 32, 48)); CGPathAddRect(thePath, NULL, CGRectMake(190, 20, 32, 48)); CAKeyframeAnimation* AniLoc = [CAKeyframeAnimation animationWithKeyPath:@"frame"]; AniLoc.path = thePath; AniLoc.keyTimes= [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f], [NSNumber numberWithFloat:0.3f], [NSNumber numberWithFloat:1.0f],nil]; AniLoc.duration = 5; CFRelease(thePath); anigroup.animations = [NSArray arrayWithObjects:AniLoc,nil]; anigroup.duration = 5; [focusview.layer addAnimation:anigroup forKey:nil]; 
+6
objective-c iphone animation core-animation uiview
source share
1 answer

You can change the size and position of the view or layer in the animation, but you want to do this as an animation group, and not by creating a path from a series of rectangles.

I present an example of a grouped animation that moves a view along a path, decreasing it and decreasing its opacity in my answer here . This works using CAKeyframeAnimation for the curved path that the view follows (only an animation of its position), and then using basic animation to adjust the size of the view borders. You can also use CAKeyframeAnimation there, with several CGSize for each keyframe of the size you wanted, making sure they wrapped them in NSValue before putting them in an NSArray of keyframes.

To animate two properties at the same time, I transfer the two animations to the CAAnimationGroup and apply them to the presentation layer.

+10
source share

All Articles