Konstantin Cherkasov
Konstantin Cherkasov

Reputation: 3343

UIButton highlight animation

Is there any way to highlight button for 0.1 sec more after touching? I'm using setImage for stateHighlighted, but my button blinks if I press it very fast.

And one more thing. In iOS 7 at the phone screen (with numbers) used very interesting animation. Highlighted button is slowly fading and then returns to normal state. Maybe somebody know, how to realise it?

Upvotes: 2

Views: 3100

Answers (1)

Abhinav
Abhinav

Reputation: 38162

You can animate ALPHA property of your UIButton

[UIView animateWithDuration:0.25 animations:^{
    yourButton.alpha = 0.0;
} completion:^(BOOL finished) {
    [UIView animateWithDuration:0.25 animations:^{
        yourButton.alpha = 1.0;
    } completion:nil];
}];

This will fade your button out over a 0.25 second period. Set the alpha to 1.0 to fade it back in again.

Upvotes: 3

Related Questions