views:

383

answers:

3

Is there a way to animate enabling or disabling a button? I've tried the following with no success. I'm guessing at this point that the enabled property cannot be animated like opacity can – but I hope I'm wrong.

 [UIView beginAnimations:nil context:nil];
 [UIView setAnimationDuration:1.0f];
 theButton.enabled = YES;
 [UIView setAnimationDelegate:self];
 [UIView commitAnimations];

I can't believe there isn't a setEnabled:(BOOL)enabled animated:(BOOL)animated method.

A: 

You can break down the enable/disable of a button into a change in opacity between two overlapping images each in one state or the other (i.e. make it look like a fade-in/fade-out). In the animation completion handler you can to do the actual enable/disable toggle.

Ramin
A: 

Here's an idea :)

Within your animation block, Remove the button from view and add it again with disabled state. You can specify what kinda animation you want here..

Prakash
I don’t see what method I could use to remove a UIBarButtonItem from the view. Also, wouldn’t this result in the button disappearing as part of the animation?
Michael Brewer
A: 

Animatable properties (through UIView beginAnimations:context:) are: frame, bounds, center, transform, alpha (from Apple docs).

So you've to determine what exactly your animation is (in terms of color/alpha/transform animations) and create manual animation (maybe you'll have to use CAAnimation instead of UIView beginAnimations:context:)

Alexander Babaev