Preethi
Preethi

Reputation: 195

UIButton image button with animation

I have a white image button. when I click, it should change into yellow button image by animating from Bottom to top and if I click yellow button image again it must animate top to bottom and change as white image button image.

This is what I tried:

    float originalY = btn.frame.origin.y; 
    float originalH = btn.bounds.size.height;

    [UIView animateWithDuration:3.0f delay:1.0f     options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{

    btn.frame = CGRectMake(btn.frame.origin.x, (originalY + originalH), btn.bounds.size.width, 0);

    [btn setBackgroundImage:[UIImage imageNamed:@"yellowimg.png"] forState:UIControlStateNormal];

    [btn setTitleColor:[[UIColor alloc]initWithRed:38.0/255.0 green:38.0/255.0 blue:38.0/255.0 alpha:1.0] forState:UIControlStateNormal];

    }    
    completion:^(BOOL finished) {
        }];

Upvotes: 3

Views: 659

Answers (1)

agoncharov
agoncharov

Reputation: 942

btn.frame = CGRectMake(btn.frame.origin.x, (originalY + originalH), btn.bounds.size.width, 0);

This method will make your button with height = 0. If you want to curl (flip) your button and to have 'new' button which appeared from the first as I know you should use something like that

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:firstView cache:YES];
[firstView addSubview:secondView];
[UIView commitAnimations];

Upvotes: 1

Related Questions