Update below with Swift 4.0
UIView.transition(with: sender as! UIView, duration: 1.5, options: .transitionFlipFromRight, animations: { sender.setImage(UIImage(named: arrItems[intItemCounter]), for: .normal) }, completion: nil)
UIButton is a subclass of UIView, so you can use UIView.animateWithDuration with a button. For example, you might say something like:
@IBAction func buttonPressed(sender: UIButton) { UIView.transitionWithView(sender, duration: 1.5, options: .TransitionFlipFromRight, animations: { sender.setImage(UIImage(named: arrItems[intItemCounter]), forState: .Normal) }, completion: nil) }
This will cause the button to switch with the new image.
If you need animation from another example (fade / in), you can say:
@IBAction func buttonPressed(sender: UIButton) { UIView.animateWithDuration(0.5, animations: { sender.alpha = 0.0 }, completion:{(finished) in sender.setImage(UIImage(named: arrItems[intItemCounter]), forState: .Normal) UIView.animateWithDuration(0.5,animations:{ sender.alpha = 1.0 },completion:nil) }) }
You can also make the cross so that:
@IBAction func buttonPressed(sender: UIButton) { UIView.transitionWithView(sender, duration: 1.5, options: .TransitionCrossDissolve, animations: { sender.setImage(UIImage(named: arrItems[intItemCounter]), forState: .Normal) }, completion: nil) }