Reputation: 323
I'm trying to set a parameter for a function but the console is stating
Use of undeclared type
rightAnimation
func slideFromRight(from: rightInAnimation.fromValue = 25) {
let rightInAnimation = CABasicAnimation(keyPath: "transform.translation.x")
rightInAnimation.duration = 0.5
rightInAnimation.fromValue = 25
rightInAnimation.toValue = 0
rightInAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
self.layer.add(rightInAnimation, forKey: "animateTranslation")
}
I'm confused. I thought I wouldn't have to declare this at top level. The intention is to be able to change the fromValue
when assigning.
Upvotes: 1
Views: 391
Reputation: 107231
The issue is with the following code:
func slideFromRight(from: rightInAnimation.fromValue = 25)
You need to change that to:
func slideFromRight(from : Int = 25)
{
let rightInAnimation = CABasicAnimation(keyPath: "transform.translation.x")
rightInAnimation.duration = 0.5
rightInAnimation.fromValue = from
rightInAnimation.toValue = 0
rightInAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
self.layer.add(rightInAnimation, forKey: "animateTranslation")
}
Upvotes: 1