How to change Frame.size using CABasicAnimation

Hi, I resized the frame using CABasicAnimation i used below code

CABasicAnimation *newanim; newanim = [CABasicAnimation animationWithKeyPath:@"bounds.size"]; newanim.duration=3.0; newanim.fromValue=[NSValue valueWithCGSize:CGSizeMake(0,0)]; newanim.toValue=[NSValue valueWithCGSize:CGSizeMake(self.backgroundImageView.bounds.size.width, self.foregroundImageView.bounds.size.height)]; newanim.fillMode=kCAFillModeForwards; newanim.autoreverses = YES; newanim.repeatCount = 1; newanim.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut]; [self.view.layer addAnimation:newanim forKey:@"changeSize"]; 

But the animation starts from the origin and moves on both sides (for example, the animation starts from the center).

I tried changing newanim = [CABasicAnimation animationWithKeyPath: @ "frame.size"];

it doesn't work at all.

+4
source share
1 answer

Apple has an answer to this question: http://developer.apple.com/library/mac/#qa/qa1620/_index.html

But personally, I don’t think this is the best way, CATransform3DMakeScale seems better:

 CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath:@"transform"]; transformAnimation.duration=3.0; transformAnimation.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeScale(scaleFactorX, scaleFactorY, scaleFactorZ)]; transformAnimation.removedOnCompletion = FALSE; [layer addAnimation:transformAnimation forKey:@"transform"]; 
+9
source

All Articles