0

I am committing this simple animation that cause a button to shrink to a width of 0:

[UIView animateWithDuration:0.2
                 delay: 0.0
                 options: UIViewAnimationOptionCurveEaseIn
                 animations:^{
                     [btnActionButton setFrame:CGRectMake(160, 10, 0, 55)];
                 }
                 completion:^(BOOL finished){
                 }];

Now the problem is that once the animation begins, the titleLabel of the button hides automatically... I made it sure using the slowAnimation mode of the simulator.

Is it possible that the label also shrinks with the frame during the animation, because it seems quite awkward if button title disappears in the beginning.

Thanks in advance. Obaid

rckoenes
  • 69,092
  • 8
  • 134
  • 166
Obaid Maroof
  • 1,523
  • 2
  • 19
  • 40

3 Answers3

3

It's due the width 0.

Use the below code.

[UIView animateWithDuration:0.2
             delay: 0.0
             options: UIViewAnimationOptionCurveEaseIn
             animations:^{
                 [btnActionButton setFrame:CGRectMake(160, 10, 50, 55)];
             }
             completion:^(BOOL finished){
             }];

in place of 50 give the width you want of button after animation.

bool.dev
  • 17,508
  • 5
  • 69
  • 93
sschunara
  • 2,285
  • 22
  • 31
1
          [UIView animateWithDuration:0.2
                      delay: 0.0
                    options: UIViewAnimationOptionCurveEaseIn
                 animations:^{
                     [btnActionButton.titleLabel setCenter:CGPointMake(-64, btnActionButton.titleLabel.center.y)];
                     [btnDeleteButton setFrame:CGRectMake(160, 10, 128, 55)];
                 }
                 completion:^(BOOL finished){
                     [btnActionButton setFrame:CGRectMake(160, 10, 0, 55)];
                     [btnActionButton.titleLabel setCenter:CGPointMake(0, btnActionButton.titleLabel.center.y)];
                 }];

This is how I managed to get it worked... Actually, I wanted to make the first button disappear and the 2nd button appear in a sliding fashion.

Obaid Maroof
  • 1,523
  • 2
  • 19
  • 40
0

Try to animate the label too. I mean like this:

[UIView animateWithDuration:0.2
             delay: 0.0
             options: UIViewAnimationOptionCurveEaseIn
             animations:^{
                 [btnActionButton setFrame:CGRectMake(160, 10, 0, 55)];
                 [btnActionButton.titleLabel setFrame:CGRectMake(  0,  0, 0, 55)];
             }
             completion:^(BOOL finished){
             }];

Hope this helps.

Cheers!

George
  • 4,029
  • 1
  • 23
  • 31
  • This doesn't work too.... seems very stupid as it is a very common animation to hide a button in a way as i shrinks to one side.... :( – Obaid Maroof Aug 24 '12 at 15:32