嘿伙计们,当表格滚动时,我试图从 UITableView 更改默认 taxtLabel 的 alpha,但我收到此错误:
Cannot invoke 'animateWithDuration' with an argument list of type '(FloatLiteralConvertible, animations: () -> () -> $T2)'
我的代码是这样的:
override func scrollViewDidScroll(scrollView: UIScrollView) {
for cell in tableView.visibleCells() {
UIView.animateWithDuration(0.5, animations: {
cell.textLabel??.alpha = 0.0
})
}
}
最佳答案
在闭包末尾添加一个空的return
语句
UIView.animateWithDuration(0.5, animations: {
cell.textLabel??.alpha = 0.0
return // <== add this
})
您正在使用具有隐式返回的紧凑(缩短)闭包版本。发生的情况是您的代码被编译器读取为:
return cell.textLabel??.alpha = 0.0
这与闭包签名不匹配,因此出现编译错误。添加 return 语句可以明确表示闭包没有返回值。
关于swift - 如何在 UITableView 中为 textLabel 的 alpha 设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26263973/