slayton
slayton

Reputation: 20319

Odd results when animating a UIButton

I am trying to animate a button such that it grows to fill the screen, holds and then shrinks to its original position. I have the animation working fine, however, there are a few oddities. The button title or image content don't scale with the button, instead they get moved to the lower right corner of the screen and then move towards the button center then as the button shrinks they move away from the button again.

Is it possible to make it so that the title of the button always remains in the center? I tried changing the content stretch as well but that crashed the emulator.

-(void) animateButton:(UIButton *)card{

[self.view bringSubviewToFront:card];

CGRect tempFrame = CGRectMake(...);
CGRect curFrame = [card getFrame];
[UIView animateWithDuration:.5 delay: 0.0 options: UIViewAnimationOptionCurveEaseIn animations:^
{
    [card setFrame:tempFrame];
  //[card setContentStrech:tempFrame];

}completion:^(BOOL finished)
{
    [UIView animateWithDuration:.5 delay: 1.0 options:UIViewAnimationOptionCurveEaseOut animations:^
    {
            [card setFrame:curFrame];
          //[card setContentStrech:curFrame];
    }completion:nil];
}]; 

}

Upvotes: 0

Views: 218

Answers (1)

Kris Van Bael
Kris Van Bael

Reputation: 2862

You should animate the Transform propery, not the frame property.

(you will see pixels though, unless you start with a large button and large font that is scaled down)

Upvotes: 1

Related Questions