ios - Swift 函数显示编译错误 "ambiguous without more context"

标签 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)
    })
}

最佳答案

多个选项的 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/

相关文章:

ios - 具有 r g b 值的 CAGradientLayer 不起作用 SWIFT

ios - Xcode - 如何修复 'NSUnknownKeyException' ,原因 : … this class is not key value coding-compliant for the key X"error?

iphone - 使用 ASIHTTPREQUEST 库发送同步请求,在 iPhone 中显示事件指示器

swift - 从镜像反省如何改变 child 的值(value)观

iOS (ObjC) PromiseKit - 在 promise 中返回 promise

mysql - 如何从 iOS 应用程序访问服务器 MySQL 数据库

ios - 如何使用 xCode 5 在新的 iOS 8 上安装应用程序?

iphone - UITextField 光标向后移动

ios - 红色组名颜色

ios - 以编程方式打开连接到导航 Controller 的 View Controller