【问题标题】:Trying to understand UIAnimation paths试图理解 UIAnimation 路径
【发布时间】:2011-11-20 00:27:54
【问题描述】:

我试图让我的动画在多个生成路径中移动。我记下了我的代码,但我仍然不明白它有什么问题。

这是我在视图中放置图像的位置

UIImageView *faceAni = [[UIImageView alloc] initWithFrame:CGRectMake(200, 100, 50.0, 50.0)];
        faceAni.animationImages = faces;
        faceAni.animationDuration = 10;
        faceAni.animationRepeatCount = 0;
        [faceAni startAnimating];
        [self addSubview:faceAni];

这是我尝试让动画在三角形路径坐标中移动的地方。

[UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1];


        [UIView animateWithDuration:4 
                              delay:0 
                            options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse  
                         animations:^{faceAni.transform = CGAffineTransformMakeTranslation(0, 200);} 
                         completion:^(BOOL finished) {

            [UIView animateWithDuration:4 
                                  delay:0 
                                options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse  
                             animations:^{faceAni.transform = CGAffineTransformTranslate(faceAni.transform, -100, 0);} 
                             completion:^(BOOL finished) {

                [UIView animateWithDuration:4 
                                      delay:0 
                                    options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse 
                                 animations:^{faceAni.transform = CGAffineTransformTranslate(faceAni.transform, 300, 0);} 
                                 completion:NULL];

            }];

        }];

我仍然不明白我的代码有什么问题。

提前致谢!

【问题讨论】:

    标签: iphone objective-c cocoa-touch core-animation


    【解决方案1】:

    如果您描述您所看到的行为可能会有所帮助。不过,作为一种猜测,您可能不希望传递给每个动画的 UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse 标志。

    【讨论】:

    • 因为我希望他们继续循环动画。所以应该以三角形移动。但是,由于图像仅从 (200, 100) 移动到 (0, 200),所以基本上它只是上下移动,而不会在我输入的其他两个坐标中移动。
    • 对;因此,只需让您的最终完成块(当前为 NULL)再次启动动画,并删除选项标志。
    • 哇,谢谢,它现在在坐标中移动,但是当它到达最后一个坐标时它不会重复。我应该在最后一个 UIView 坐标选项中返回选项吗?
    • 不,这只会重复上一个动画。您应该在最后一个动画上有一个完成块,它调用该方法再次运行动画。如果您觉得我的回答有帮助,请点击答案旁边的复选标记接受它是有礼貌的。
    • 对不起,我有点迷路了。在我的完成块中我应该调用什么方法?
    猜你喜欢
    • 2015-09-20
    • 1970-01-01
    • 2011-06-30
    • 1970-01-01
    • 2012-03-05
    • 2013-11-13
    • 2023-03-10
    • 2014-09-23
    • 2013-11-26
    相关资源
    最近更新 更多