嗨,我已经使用下面代码中使用的 CABasicAnimation 更改了帧大小
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"];
但是动画从原点开始并移动到两边(就像动画从中心开始)。
我尝试通过改变
newanim = [CABasicAnimation animationWithKeyPath:@"frame.size"];
它根本不起作用。
最佳答案
苹果对此有一个答案:http://developer.apple.com/library/mac/#qa/qa1620/_index.html
但我个人认为这不是最好的方法,CATransform3DMakeScale 似乎更好:
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"];
关于cocoa-touch - 如何使用 CABasicAnimation 更改 Frame.size,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3615307/