0

我正在开发一个水族馆应用程序。我需要在其中生成鱼的运动。鱼应该游泳,当到达水族箱的一端时,应该转弯(或翻转)并移动到另一端,再次转弯(或翻转)并返回其原始位置。

鱼前移运动正常工作,它也轮流(翻转)到达终点。但是当它到达另一端时,翻转动画和进一步的动画会突然跳过。

以下是我正在使用的代码.....

CGFloat originalChildXpos = fishView.frame.origin.y;

/************************************** Animation 1 **************************************************************/

[UIView animateWithDuration:15.0
                      delay:1.0
                    options:UIViewAnimationOptionCurveEaseInOut
                 animations:^{                         
                     fishView.frame =CGRectMake(0, fishView.frame.origin.y, fishView.frame.size.width, fishView.frame.size.height);                         
                 }completion:NULL];


/*********************************** Animation 2 ****************************************************************/
[UIView animateWithDuration:2.4
                      delay:3.0
                    options:UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     fishView.transform = CATransform3DGetAffineTransform(CATransform3DMakeRotation(M_PI, 0.0, 1.0, 0.0));

                 }completion:NULL];



/********************************* Animation 3 ****************************************************************/
[UIView animateWithDuration:10
                      delay:3.4
                    options:UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     fishView.frame = CGRectMake(-aquariumView.frame.size.width, fishView.frame.origin.y, fishView.frame.size.width, fishView.frame.size.height);
                 }completion:NULL];



/*************************************** Animation 4 *****************************************************/
[UIView animateWithDuration:1.4
                      delay:13.4
                    options:UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     fishView.transform = CATransform3DGetAffineTransform(CATransform3DMakeRotation(-M_PI, 0.0, 1.0, 0.0));

                 }completion:NULL];


/************************************* Animation 5 *******************************************/
[UIView animateWithDuration:13.8
                      delay:2.2
                    options:UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     fishView.frame = CGRectMake(originalChildXpos, fishView.frame.origin.y, fishView.frame.size.width, fishView.frame.size.height);
                 }completion:NULL];

我想我在使用CATransform3DGetAffineTransform(CATransform3DMakeRotation())函数时错过了一些东西,第二次翻转旋转.....

这里的任何人都可以告诉我如何摆脱它并解释我哪里出错了

我还想知道在使用CATransform3D旋转时,相对于视图的坐标轴是否会改变或生效?

4

1 回答 1

0
  CGFloat originalChildXpos = fishView.frame.origin.y;
    CGAffineTransform currentTransform=fishView.transform; // step one add this

    /************************************** Animation 1 **************************************************************/

    [UIView animateWithDuration:15.0
                          delay:1.0
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{                         
                         fishView.frame =CGRectMake(0, fishView.frame.origin.y, fishView.frame.size.width, fishView.frame.size.height);                         
                     }completion:NULL];


    /*********************************** Animation 2 ****************************************************************/
    [UIView animateWithDuration:2.4
                          delay:3.0
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         fishView.transform = CATransform3DGetAffineTransform(CATransform3DMakeRotation(M_PI, 0.0, 1.0, 0.0));

                     }completion:NULL];



    /********************************* Animation 3 ****************************************************************/
    [UIView animateWithDuration:10
                          delay:3.4
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         fishView.frame = CGRectMake(-aquariumView.frame.size.width, fishView.frame.origin.y, fishView.frame.size.width, fishView.frame.size.height);
                     }completion:NULL];



    /*************************************** Animation 4 *****************************************************/
    [UIView animateWithDuration:1.4
                          delay:13.4
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         fishView.transform = currentTransform;  // step 2 replace here 

                     }completion:NULL];


    /************************************* Animation 5 *******************************************/
    [UIView animateWithDuration:13.8
                          delay:2.2
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         fishView.frame = CGRectMake(originalChildXpos, fishView.frame.origin.y, fishView.frame.size.width, fishView.frame.size.height);
                     }completion:NULL];

对于变换,你在初始时做了 x = y,所以现在你的 x 变成了 y,在下一个语句中你改变了 y =y 所以没有效果......

于 2013-04-17T10:11:32.993 回答