how to check if amination isAnimated and respond accordingly??

Discussion in 'iOS Programming' started by moomy, Oct 7, 2010.

  1. moomy macrumors newbie

    Joined:
    Apr 28, 2010
    #1
    Hi guys,

    I have a simple UIImage animation, it works well but it can be called again mid animation, this runs the second go of animation over the first and looks a mess. I really want it so that it can only be called to animate again once it has finished animating. I'm guessing that I need to use the isAnimating BOOL but am not sure how to do this??

    here is the code I have so far.

    Code:
    
    -(IBAction) aura{
    	
    	NSArray * auraArray = [[NSArray alloc] initWithObjects:
    							
    							// [UIImage imageNamed:@"smallblink.png"],
    							[UIImage imageNamed:@"aura1.png"],
    							
    							[UIImage imageNamed:@"aura1-2.png"],
    							[UIImage imageNamed:@"aura1-2-3.png"],
    							[UIImage imageNamed:@"aura1-2-3-4.png"],
    							[UIImage imageNamed:@"aura1-2-3-4-5.png"],
    						   [UIImage imageNamed:@"evenmoreAura.png"],
    						      [UIImage imageNamed:@"evenmoreAura.png"],
    						   [UIImage imageNamed:@"evenmoreAura.png"],
    						   [UIImage imageNamed:@"evenmoreAura.png"],
    
    						   [UIImage imageNamed:@"aura1-2-3-4-5.png"],
    						    [UIImage imageNamed:@"aura1-2-3-4.png"],
    						    [UIImage imageNamed:@"aura1-2-3.png"],
    						   	[UIImage imageNamed:@"aura1-2.png"],
    							//[UIImage imageNamed:@"biggyshock.png"],
    							
    							nil];
    	UIImageView * aura = [[UIImageView alloc] initWithFrame:CGRectMake(100, 40, 90, 20)];
    	aura.animationImages = auraArray;
    	aura.animationDuration = 1.30;
    	aura.animationRepeatCount = 1;
    	aura.contentMode = UIViewContentModeTop;
    	[self.view addSubview:aura];
    	[aura startAnimating];
    	
    	
    	
    	[aura release];
    	[auraArray release];
    	
    	
    	
    }
    
    I think this may be simple for an experienced programmer but as a noob I'm finding it a bit tricky.
    thanks
    moomy
     
  2. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #2
    Firstly, as presented, the code adds a new UIImageView to self every time the IBAction is triggered. Is that correct?

    Secondly, what should happen if the IBAction is triggered during an animation? Nothing? Restart the animation? Or something else?

    Are you familiar with the 'if' statement?
     
  3. moomy thread starter macrumors newbie

    Joined:
    Apr 28, 2010
    #3
    Hi there,

    ideally I would like the button to do nothing if the animation is already running.

    I guess I need a way to say, if animation is running do nothing else run animation.

    if (isAnimating == YES)
    {

    return;
    }
    isAnimating = YES;

    something like that??
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    isAnimating is an instance method of UIImageView. You should use it accordingly.
     

Share This Page