Please Help: How to link 2 animations in 1 IBAction??

Discussion in 'iOS Programming' started by tomgoodenough, Sep 10, 2010.

  1. tomgoodenough macrumors newbie

    Joined:
    Sep 10, 2010
    #1
    ok i have an ibaction looks like this:


    Code:
    -(IBAction)animatego {
    	
    	NSTimer *animateTime = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(animate) userInfo:nil repeats:YES];
    	
    	
    	
    }
    
    -(void)animate {
    	
    	if (animated == FALSE) {
    		
    		[UIView beginAnimations:nil context:NULL];
    		[UIView setAnimationDuration:2.0];
    		dmImage.transform = CGAffineTransformMakeTranslation(0, -600);
    		dmImage.alpha = 1.0;
    		[UIView commitAnimations];
    
    		animated = TRUE;
    	} else {
    		
    		[UIView beginAnimations:nil context:NULL];
    		[UIView setAnimationDuration:1.5];
    		dmImage.alpha = 1.0;
    		[UIView commitAnimations];
    		animated = FALSE;
    		
    		
    	}
    so its part of the code to make the image go up out of the screen. then in the SAME IBAction, how can i make the image come back down again? I have tried copying parts of the code and altering them but errors come up :(

    so bottom line:

    How to animate an image up and back down again in ONE animation?
     
  2. bindle macrumors regular

    Joined:
    Aug 29, 2008
    #2
    Just link multiple animations together is using setAnimationDidStopSelector. It will call the next animation after the current one ends.

    Code:
    
    - (void)animationFirst {
    
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(animationSecond)];
    
        //image up
    
        [UIView commitAnimations];
    }
    
    - (void)animationSecond {
    
        [UIView beginAnimations:nil context:NULL];
    
        //image down
    
        [UIView commitAnimations];
    }
    
     
  3. tomgoodenough thread starter macrumors newbie

    Joined:
    Sep 10, 2010
    #3
    great thanks, but it says the void is undeclared??
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    Copy and paste the complete error message.
    Your description is too vague.
     
  5. tomgoodenough thread starter macrumors newbie

    Joined:
    Sep 10, 2010
    #5
    says: "animationFirst" undeclared.

    How do i declare the void as it is:

    - (void)animationFirst
     
  6. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #6
    Post the code that causes the error.
    All the code, not just part of it.


    It's correct in bindle's earlier post. So something else is wrong. That's why we need to see all the code that causes the error.
     
  7. ianprime0509 macrumors newbie

    Joined:
    Aug 31, 2010
    #7
    Did you also declare the function in the .h file?
     
  8. Sykte macrumors regular

    Joined:
    Aug 26, 2010
    #8
    By chance did you keep the name of your method but changed the (IBAction) -> (void) and then copy/paste the given code. Take a look in IB and verify the connection. Also check both your header/implementation files and verify your first method in the chain has a return of (IBAction).
     

Share This Page