2

I am new to iPhone development. I am using UIImageView to animate the images in an array. I am deciding that the animation is stopped through a property called isAnimating. But it always returns true.

I want to check that the animation is completed or there is some duration left to complete the animation.

Please let me know, how I can check it.

Andrey Zverev
  • 4,409
  • 1
  • 28
  • 34
Pravin Prasad
  • 223
  • 6
  • 14

3 Answers3

1

Make a property BOOL IsAnimating then do this code

{
     [UIView beginAnimations:@"Animation of ImageVIew Begins" context:nil];
           IsAnimating =YES;

     [UIView setAnimationDuration:0.4]; //you can put your time
     NSLog(@" Animating");
     [UIView setAnimationDelegate:self];
     [UIView setAnimationDidStopSelector:@selector(AnimationComplete)];

// Your animation code here     
     [UIView commitAnimations];
}


- (void) AnimationComplete
{
  isAnimating = NO;
}

Your BOOl variable will be YES till the animation is complete..then it will change to NO

Shubhank
  • 21,721
  • 8
  • 65
  • 83
  • I'd up-vote this — if not sticking to the [naming conventions](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingBasics.html#//apple_ref/doc/uid/20001281-1002931-BBCFHEAB) wouldn't bug me so much – vikingosegundo Feb 03 '12 at 20:28
0

Use a delegate based on the duration to trigger whatever method you want on the receiver.

martin's
  • 3,853
  • 6
  • 32
  • 58
-4

you should be doing your animation inside animation blocks:

[UIView animateWithDuration:duration animations:^{
    //animation code here
} completion:^(BOOL finished)
{
    //this will be called when the animation is finished
}];

edit: this answer is wrong and probably shouldnt have been accepted, for anyone coming here looking for the right answer: this answers this question i think

Community
  • 1
  • 1
wattson12
  • 11,176
  • 2
  • 32
  • 34
  • 1
    That I know, `animateWithDuration:completion:` is used to do iOS animations (such as alpha fade, motion, scaling, rotation, etc.) I see that he accepted this answer, but I believe the original question had to do with detecting the end of a `UIImageView`'s animating an array of UIImages by setting the `animationImages` property. I'd love to see an answer that talked about how to detect the end of that set of animations. – Olie Nov 01 '12 at 22:13