user4809833
user4809833

Reputation:

Why rotation happens just one time?

How can I rotate my view on each button click?

When I try to:

@IBAction func replaceCurrencies(sender: AnyObject) {
    UIView.animateWithDuration(Double(0.5), animations: {
        self.arrows.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
    }
}

it rotates just one time. It do not rotate for the next my clicks. How can I fix it?

Upvotes: 1

Views: 39

Answers (1)

rkyr
rkyr

Reputation: 3241

This is because when you push your button again your view already have this transform. You need to reset it to CGAffineTransformIdentity or rotate from current transform. Second way is preferable because it will not jump to start before rotating:

@IBAction func replaceCurrencies(sender: AnyObject) {
    UIView.animateWithDuration(0.5, animations: {
        self.arrows.transform = CGAffineTransformRotate(self.arrows.transform, CGFloat(M_PI))
    })
}

Upvotes: 3

Related Questions