Jhonny Everson Jhonny Everson - 5 months ago 85
Objective-C Question

Animate UIButton state change

I'm using a UIButton with images for normal and highlighted states. They work as expected but I want to have some fading/merging transition and not just a sudden swap.

How can I do that?

Answer

This can be done using transition animation of an UIView.

Swift

UIView.transitionWithView(button, 
                          duration: 4.0, 
                          options: .TransitionCrossDissolve, 
                          animations: { button.highlighted = true },
                          completion: nil)

Objective-C

[UIView transitionWithView:button
                  duration:4.0
                   options:UIViewAnimationOptionTransitionCrossDissolve
                animations:^{ button.highlighted = YES; }
                completion:nil];