0

The image in this code grows from the center until it reaches its final size and then stops. What I need is to also make the image move to the bottom center while it's growing. Thank you.

- (IBAction)expand:(id)sender {


    grow.transform = CGAffineTransformMakeScale(1,1);

        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:5.7];
    grow.transform = CGAffineTransformMakeScale(5, 5);

        [UIView setAnimationRepeatAutoreverses:YES];
    self.view.transform = CGAffineTransformIdentity;

        [UIView setAnimationCurve:UIViewAnimationCurveLinear];

        grow.alpha = 1.0;


        [UIView commitAnimations];


    }
4

2 回答 2

0

刚刚找到答案,它对我有用。我在我的第一个代码之后添加了这个并获得了预期的效果。这是代码:

成长中心 = CGPointMake(150, 650);

[UIView animateWithDuration:5.0
                 animations:^{grow.center= CGPointMake(160, 244);}];

我必须关闭自动布局才能正常工作。

再次感谢 Xono 的回答和回复 :)

于 2013-10-24T21:18:43.617 回答
0

有几种方法可以解决这个问题。您使用的动画代码技术在 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];
于 2013-10-23T23:31:40.527 回答