尝试在 Swift 中将变量传递给我的动画时出现以下错误:
Could not find member 'CurveEaseOut'
如果我手动输入度数,我的代码似乎没问题:
UIView.animateWithDuration(2.0, delay: NSTimeInterval(0.0), options: .CurveEaseOut, animations: {
self.arrowImage.transform = CGAffineTransformMakeRotation((180.0 * CGFloat(M_PI)) / 180.0)
}, completion: nil)
但是如果我尝试使用变量,我会遇到问题:
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)
也许这是我对 Double() 的使用?我尝试了各种不同的类型,但找不到解决方案。
最佳答案
.CurveEaseOut 没有任何问题。我认为问题出在闭包中。
试试这个
var turn:CGFloat = 180.0
如果错误仍然存在,则 arrowImage 是可选的,您必须使用 if let 来展开它
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)
关于swift - Swift 中的 animateWithDuration - 找不到成员 'CurveEaseOut',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29394624/