views:

361

answers:

3

Hello again SO peeps!

Basically, I am trying to UIViewAnimationTransitionCurlUp a UIButton. The animation works perfectly but the button stays there.

i.e. The button curls up, but there is another instance of the button still underneath.

My code as follows:

[UIButton beginAnimations:nil context:nil];
[UIButton setAnimationDuration:0.5];
[UIButton setAnimationBeginsFromCurrentState:YES];
[UIButton setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIButton commitAnimations];
+2  A: 

You have to remove the button (hide the button) when the animation ends.This should be done in

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context

which should be set in animation code

like:

[UIButton setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

Hope this helps.

Thanks,

Madhup

Madhup
Excellent, cheers!
Neurofluxation
Afraid this still isn't working correctly - I'm obviously missing something simple.
Neurofluxation
A: 

Ok, I should of probably checked this before I voted you up...

The button is still not dissapearing after the animation has finished :(

My code is now:

[UIButton beginAnimations:@"welcomeAnimation" context:nil];
[UIButton setAnimationDuration:0.5];
[UIButton setAnimationDidStopSelector:@selector(welcomeAnimationDidStop:finished:context:)];
[UIButton setAnimationBeginsFromCurrentState:YES];
[UIButton setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIButton commitAnimations];

and my method:

-(void)welcomeAnimationDidStop:(NSString *)animationID finished:(BOOL *)finished context:(void *)context {
   welcomeButton.hidden = YES;
}
Neurofluxation
+3  A: 

Set new button state between +beginAnimations and +commitAnimations calls. Following code hides clicked button with curl animation:

- (void)btnClick:(id)sender{
    [UIButton beginAnimations:nil context:nil];
    [UIButton setAnimationDuration:0.5];
    [UIButton setAnimationBeginsFromCurrentState:YES];
    [UIButton setAnimationTransition:UIViewAnimationTransitionCurlUp 
                                  forView:(UIView*)sender cache:YES];
    ((UIView*)sender).hidden = YES;

    [UIButton commitAnimations];
}
Vladimir
That, my friend, was perfect! +1up
Neurofluxation