有几种方法可以解决这个问题。您使用的动画代码技术在 iOS4 中已被替换,并且 CGAffineTransform 的使用(在我看来)也不是很理想。
尽管如此,如果你想使用这种方法,你可以做类似的事情(注意:我没有测试过,这或多或少是一个最好的猜测):
- (IBAction)expand:(id)sender {
grow.transform = CGAffineTransformMakeScale(1,1);
CGFloat scale = 5.0;
CGFloat moveDistance = ([[UIScreen mainScreen] bounds].size.height - (grow.frame.origin.y*scale)) - grow.frame.origin.y;
CGAffineTransform transformation = CGAffineTransformMakeScale(scale, scale);
transformation = CGAffineTransformTranslate(transformation, 0, moveDistance);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5.7];
grow.transform = transformation;
[UIView setAnimationRepeatAutoreverses:YES];
self.view.transform = CGAffineTransformIdentity;
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
grow.alpha = 1.0;
[UIView commitAnimations];
}
我建议尽管研究使用基于块的动画方法 - 它更简单且更具可读性。此外,使用 CGAffineTransform 放大有时会导致问题(例如,如果增加 UILabel 框架的大小,它只会重新定位文本。如果使用 CGAffineTransform,文本会放大,变得像素化)。你可以做类似这样的事情:
CGFloat scale = 5.0;
CGRect originalFrame = grow.frame;
CGRect targetFrame = CGRectMake(
originalFrame.origin.x-(originalFrame.size.width*(scale/2.0)),
[[UIScreen mainScreen] bounds].size.height - (originalFrame.size.height*scale),
originalFrame.size.width*scale,
originalFrame.size.height*scale);
[UIView animateWithDuration:5.7 delay:0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{
[UIView setAnimationRepeatCount:1]
grow.frame = targetFrame;
grow.alpha = 1.0;
} completion:nil];