Can someone help me understand how I can get an animation to repeat until a sound file has finished playing? Right now I have a button that plays a sound and fires this animation code. The animation is set to repeat 3 times, but my sound files are differing lengths. So my animation is not always in synch with my sound.
Code:
- (void) itemAnimate {
// starts the animation
[UIView beginAnimations:nil context:NULL];
// sets the length of the animation
[UIView setAnimationDuration:.25];
// tells animation to play backward, needs RepeatCount to work
[UIView setAnimationRepeatAutoreverses:YES];
// sets number of times animation repeats, default value is 0, which specifies to repeat the animation indefinitely; and 1e100f means go until removed from view
[UIView setAnimationRepeatCount:3];
// moves the animated area
itemView.transform = CGAffineTransformTranslate(mouthView.transform, 0.0, 20.0);
// resets the position of view
itemView.transform = CGAffineTransformIdentity;
// ends animation
[UIView commitAnimations];
}
I see that there is a callback that can be used when a sound is done playing, but how would I use it to stop an animation in progress?
Did you ever find a solution to this question, I am searching for the same thing?
Thank you!
Quote:
Originally Posted by DenVog
Can someone help me understand how I can get an animation to repeat until a sound file has finished playing? Right now I have a button that plays a sound and fires this animation code. The animation is set to repeat 3 times, but my sound files are differing lengths. So my animation is not always in synch with my sound.
Code:
- (void) itemAnimate {
// starts the animation
[UIView beginAnimations:nil context:NULL];
// sets the length of the animation
[UIView setAnimationDuration:.25];
// tells animation to play backward, needs RepeatCount to work
[UIView setAnimationRepeatAutoreverses:YES];
// sets number of times animation repeats, default value is 0, which specifies to repeat the animation indefinitely; and 1e100f means go until removed from view
[UIView setAnimationRepeatCount:3];
// moves the animated area
itemView.transform = CGAffineTransformTranslate(mouthView.transform, 0.0, 20.0);
// resets the position of view
itemView.transform = CGAffineTransformIdentity;
// ends animation
[UIView commitAnimations];
}
I see that there is a callback that can be used when a sound is done playing, but how would I use it to stop an animation in progress?
Did you ever find a solution to this question, I am searching for the same thing?
Thank you!
It has been a long time. I don't think you can stop the animation directly, but can stop a timer. So as I recall I run the animation with a timer on repeat. I then use the callback from when the sound completes to invalidate the timer (thus stopping the animation). Does that help?
Not sure. Don't know about the callback when sound completes, have not read about that and if there is a callback when the sound completes why do you need a timer? Couldn't you just execute the next function and call next screen once you are alerted the sound has finished? How do I get it to tell me when a sound file is done playing, that seems very useful?
Thanks!
Quote:
Originally Posted by DenVog
It has been a long time. I don't think you can stop the animation directly, but can stop a timer. So as I recall I run the animation with a timer on repeat. I then use the callback from when the sound completes to invalidate the timer (thus stopping the animation). Does that help?
Not sure. Don't know about the callback when sound completes, have not read about that and if there is a callback when the sound completes why do you need a timer? Couldn't you just execute the next function and call next screen once you are alerted the sound has finished? How do I get it to tell me when a sound file is done playing, that seems very useful?
Thanks!
Search for forum for "completionCallback".
The thread I started was about stopping an animation, not switching screens. As I stated, I don't think you can stop an animation directly. Stopping a timer that was running an animation worked for me..