views:

249

answers:

2

I'm creating a menu and I want the buttons to "pop" I guess on the screen. Basically I want to start at 0px dimensions and then go up to the full size of the buttons. I can animate the alpha and the position if I want to but can't do the dimensions and I think its because its an image on the button.

If I do a UIButtonTypeRoundRect you can see the button being animated behind the image but the image is static.

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:@"settings.png"] forState:UIControlStateNormal];
button.frame = CGRectMake(20, 20, 0, 0);
button.alpha = 0;
[self.view addSubview:button];
CGRect frame = button.frame;
[UIView beginAnimations:@"button" context:nil];
[UIView setAnimationDuration:1];
button.alpha = 1;
frame.size.width += 53;
frame.size.height += 53;
button.frame = frame;
[UIView setAnimationDelegate:self];
[UIView commitAnimations];

So the Alpha works but the resize doesn't. I've also played with stretchableImageWithLeftCapWidth to try and give it context or something but to no avail.

Cheers for your help.

+2  A: 

Could you try using the following code instead?

button.transform = CGAffineTransformMakeScale(1.5,1.5);
button.alpha = 0.0f;

[UIView beginAnimations:@"button" context:nil];
[UIView setAnimationDuration:1];
     button.transform = CGAffineTransformMakeScale(1,1);
     button.alpha = 1.0f;
[UIView commitAnimations];

Your button should start slightly larger and then shrink back down. If this scales properly, just adjust the scalefactor before and after to suit.

davbryn
Thanks, I'll have a look and get back to you.
Rudiger
That didn't work straight away. Button = CGAffineTransformMakeScale(1.5,1.5); threw an error. But basically you can do the button.transform = CGAffineTransformMakeScale(1.5,1.5); and it animates a scale increase like I needed. Thanks :)
Rudiger
Great stuff - I've amended the code sample for anyone else who might want to use it
davbryn
A: 

thaanx alot.....it works

Syed Sami ul Ahbab