1

我在处理动画块时遇到了困难。我试图让第一个动画改变图像的 alpha 使其闪烁,然后在 10 秒后消失。firstAnimation 然后移动到 secondAnimation ,它只对不同的图像执行相同的操作。然后这个过程会无限重复。

我已经为此工作了一段时间,无法让它无限重复。我遇到的另一个问题是这个动画过程延迟 - 所以它在 20 秒后开始,足够播放音频文件的时间。

- (void) firstAnimation {
            UIViewAnimationOptions options = UIViewAnimationOptionCurveLinear;

            [UIView animateWithDuration:1.0 delay:10.0 options:options animations:^ 
            {
                    myImage.alpha = 0.0;
                    myImage.alpha = 1.0;

            }

                    completion:^(BOOL finished){

                    [self secondAnimation]; 
            }
             ];

    }

一如既往地感谢您的帮助。我已经搜索了示例代码和教程,但我发现的基本上都是我在上面的代码中所做的。

4

2 回答 2

1

我认为你必须在动画块之外设置你的 alpha 的初始值,并且只有你希望它在块内设置动画的值。

UIViewAnimationOptions options = UIViewAnimationOptionCurveLinear;
myImage.alpha = 0.0;
[UIView animateWithDuration:1.0 delay:10.0 options:options animations:^ 
        {
                myImage.alpha = 1.0;

        }
于 2010-10-14T13:01:34.903 回答
1
animateImageWithCount:(int)aCount{
    if( aCount >= [imageArray count]){
        NSLog(@"Done all images");
        return;
    }

    UIImage *myImage = [ImageArray objectAtIndex:aCount];
    UIViewAnimationOptions options = UIViewAnimationOptionCurveLinear;

    myImage.alpha = 0.0;
    [UIView animateWithDuration:1.0 delay:10.0 options:options animations:^{
        myImage.alpha = 1.0;
    }
    completion:^(BOOL finished){
        [self animateImageWithCount:(aCount+1)];
     }];
}
于 2011-12-23T05:36:23.280 回答