Rotate image -45 degrees
<p>I am building example about <strong>FloatingButton</strong>.</p>

<p>But I have some troubles with rotate image. I want it to rotate like this link </p>

<p><a href="https://github.com/yoavlt/LiquidFloatingActionButton" rel="noreferrer">https://github.com/yoavlt/LiquidFloatingActionButton</a></p>

<p>But my button is:</p>

<p><a href="https://i.stack.imgur.com/poId4.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/poId4.gif" alt="enter image description here"></a></p>

<p>As you can see, when I click the first time, it run well :D, it transform like <code>x</code>, but when I click again, I want it back to original like <code>+</code>, but it doesn't work well.</p>

<p>Here is my code:</p>

<pre><code>import UIKit

class ViewController: UIViewController {

    @IBOutlet var floatingButton: UIImageView!
    var floatingButtonIsActive = false

    override func viewDidLoad() {
        super.viewDidLoad()

        addShadowToFloatingButton()
        let gesture = UITapGestureRecognizer(target: self, action: #selector(floatingButtonTapped(_:)))
        floatingButton.addGestureRecognizer(gesture)
    }

    private func addShadowToFloatingButton() {
        floatingButton.layer.shadowColor = UIColor.grayColor().CGColor
        floatingButton.layer.shadowOffset = CGSize(width: -2, height: 2)
        floatingButton.layer.shadowOpacity = 1
        floatingButton.layer.shadowRadius = 1
    }

    func floatingButtonTapped(sender: UITapGestureRecognizer) {

        if floatingButtonIsActive == false {

            UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 5, options: .CurveEaseInOut, animations: {
                self.floatingButton.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_4))
                }, completion: { _ in
                    self.floatingButtonIsActive = true
            })

        } else {
            UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 5, options: .CurveEaseInOut, animations: {
                self.floatingButton.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI_4))
                }, completion: { _ in
                    self.floatingButtonIsActive = false
            })
        }
    }
}
</code></pre>