1)我正在使用变量作为第一个参数,UIView.animateWithDuration如下所示:
var theDelay: Float = 1.0
UIView.animateWithDuration( theDelay, animations: {
cell.frame.origin.y = 0
})
Run Code Online (Sandbox Code Playgroud)
和Xcode6(Beta 3)给我一个构建错误:'在调用中'参数'延迟'缺少参数'.
当我不使用变量时,该函数工作得很好.当我发现这个问题时,我想调整变量(因为这段代码在循环中).
2)或者,我可以跳过使用变量并包括在线计算:
UIView.animateWithDuration( indexPath.row * 1.0, animations: {
cell.frame.origin.y = 0
})
Run Code Online (Sandbox Code Playgroud)
但是我得到了同样的错误'在参数'参数'延迟'中缺少参数'.
我在这做错了什么?
错误消息具有误导性.第一个参数animateWithDuration()
具有类型NSTimeInterval(即a Double),但是您传递Float参数.Swift不会隐式转换类型.
将变量定义更改为
let theDelay = 1.0
Run Code Online (Sandbox Code Playgroud)
或明确的转换
UIView.animateWithDuration(NSTimeInterval(indexPath.row), animations: {
cell.frame.origin.y = 0
})
Run Code Online (Sandbox Code Playgroud)
应该解决问题.
在Swift 3中,这将是
let theDelay = TimeInterval(indexPath.row)
UIView.animate(withDuration: theDelay, animations: {
cell.frame.origin.y = 0
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10954 次 |
| 最近记录: |