views:

34

answers:

1

I'm having difficulty working with the animation blocks. I'm trying to have the first animation change the alpha of an image so that it flashes, then after 10 seconds disappears. the firstAnimation then moves to secondAnimation which does the same thing only to a different image. the process then repeats itself infinitely.

I've been working w/ this for a while now and cannot make it repeat infinitely. Another problem I had was having this animation process delay - so that it begins after 20 seconds, enough time for an audio file to play.

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

    }

thanks as always, for any help. I've searched for example code and tutorials but all I found is basically what I'm doing in the code above.

+1  A: 

I think you have to set the initial value of your alpha outside the animation block and only the value you want it to animate to inside the block.

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

        }
Ben
thanks! that worked nicely. Do you know how I could then put that on an infinite loop? thanks again
hanumanDev
You should be able to achieve that by chaining the functions in the way you have above. First anim calls the second which calls the first etc. Any more complicated than that and I would suggest using an NSTimer to call the firstanimation function every X seconds for infinity.
Ben
ok, thanks. maybe I should use an NSTimer because I want the animations to begin after an audio clip plays.
hanumanDev