为什么这个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)
})
}
答案 0 :(得分:2)
多个选项的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]