Swift函数显示编译错误“模糊而没有更多上下文”

时间:2016-01-08 19:59:52

标签: ios xcode swift

为什么这个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)
    })
}

1 个答案:

答案 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]