我试图为某个功能设置参数,但控制台正在说明
使用未声明的类型
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") }
fromValue
我很困惑。我以为我不必在顶级声明这个。目的是在分配时能够更改{{1}}。
答案 0 :(得分:1)
问题在于以下代码:
func slideFromRight(from: rightInAnimation.fromValue = 25)
您需要将其更改为:
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")
}