为什么这个 Swift 函数现在需要更多上下文?这显示在带有 .CurveLinear
func playSequence(index:Int,highlightTime:Double){
currentPlayer = .Computer
if index == inputs.count{
currentPlayer = .Human
return
}
var button:UIButton = buttonByColor(inputs[index])
var originalColor:UIColor? = button.backgroundColor
var highlightColor:UIColor = UIColor.whiteColor()
UIView.animateWithDuration(highlightTime,delay: 0.0,options: .CurveLinear & .AllowUserInteraction & .BeginFromCurrentState,
animations:{
button.backgroundColor = highlightColor
}, completion: {
finished in button.backgroundColor = originalColor
var newIndex:Int=index+1
self.playSequence(newIndex, highlightTime: highlightTime)
})
}
最佳答案
多个选项的 Swift 2 语法需要在方括号中设置一个选项。在您的 animateWithDuration 中,您需要创建一个选项集:
UIView.animateWithDuration(highlightTime,delay: 0.0,options:[.CurveLinear, .AllowUserInteraction, .BeginFromCurrentState],
animations:{
button.backgroundColor = highlightColor
}, completion: {
finished in button.backgroundColor = originalColor
var newIndex:Int=index+1
self.playSequence(newIndex, highlightTime: highlightTime)
})
你也可以像这样显式地定义一个集合:
let mySet : UIAnimationOptions = [.CurveLinear, .AllowUserInteraction, .BeginFromCurrentState]
关于ios - Swift 函数显示编译错误 "ambiguous without more context",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34685117/