Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tomgoodenough

macrumors newbie
Original poster
Sep 10, 2010
13
0
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?
 
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];
}
 
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).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.