试图了解UIAnimation路径

时间:2011-11-20 00:27:55

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

我试图让我的动画在多个生成的路径中移动。我得到了我的代码,但我仍然没有弄到它的错误。

这是我将图片放在视图中的位置

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];

            }];

        }];

我仍然不知道我的代码有什么问题。

提前致谢!

1 个答案:

答案 0 :(得分:0)

如果您描述您所看到的行为,这可能会有所帮助。但是,您可能不希望将UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse标记传递给每个动画。