Reputation: 673
I get the following error when attempting to pass a variable in to my animation in Swift:
Could not find member 'CurveEaseOut'
My code seems fine if I type the degrees in manually:
UIView.animateWithDuration(2.0, delay: NSTimeInterval(0.0), options: .CurveEaseOut, animations: {
self.arrowImage.transform = CGAffineTransformMakeRotation((180.0 * CGFloat(M_PI)) / 180.0)
}, completion: nil)
But I have the issue if I attempt to use a variable:
var turn = Double()
turn = 180.0
UIView.animateWithDuration(2.0, delay: NSTimeInterval(0.0), options: .CurveEaseOut, animations: {
self.arrowImage.transform = CGAffineTransformMakeRotation((turn * CGFloat(M_PI)) / turn)
}, completion: nil)
Perhaps it's my use of Double()? I've tried various different types and can't find a solution.
Upvotes: 1
Views: 1084
Reputation: 6781
Problem is because you're using the variable turn. You're using turn inside a closure and you must use self.turn because turn is declared outside the scope of the animation closure.
Weird but that's how it is :\
Upvotes: 0
Reputation: 3759
There is nothing wrong with .CurveEaseOut. The problem i think is within the closure.
Try this
var turn:CGFloat = 180.0
If the error remains then arrowImage is optional and you have to use if let to unwrapped it
UIView.animateWithDuration(2.0, delay: NSTimeInterval(0.0), options: .CurveEaseOut, animations: {
if let ai = self.arrowImage {
ai.transform = CGAffineTransformMakeRotation((turn * CGFloat(M_PI)) / turn)
}
}, completion: nil)
Upvotes: 1
Reputation: 5590
You could do two things. You could either
let turn: CGFloat = 180.0
or
CGAffineTransformMakeRotation((CGFloat(turn) * CGFloat(M_PI)) / CGFloat(turn))
Since Swift is type safe it's expecting a CGFloat passed to CGAffineTransformMakeRotation
Upvotes: 1