我正在遵循此处列出的代码:Dropdown list in swift
即:
func animateDropDownToFrame(frame: CGRect, completion:() -> Void) {
if (!self.isAnimating) {
self.isAnimating = true
UIView.animateWithDuration(0.5, delay: 0.0, options: .CurveEaseInOut, animations: { () -> Void in
self.dropDownView.frame = frame
}, completion: {(completed: Bool) -> Void in
self.isAnimating = false
if (completed) {
completion()
}
}
)
}
}
并继续在完成时获取错误:
Expected ',' separator
Expected member name or constructor call after type name
请注意,我对完成行进行了一些更改,因为我认为括号位于错误的位置,但我不认为这就是问题所在。
可能是什么问题(以及我自己调试此问题的最佳方法是什么)?
最佳答案
所写的语法很难理解。 Swift 编译器也可能存在一个错误,导致它无法解析您编写的内容。 Swift 允许嵌套函数,因此您可以执行以下操作:
func animateDropDownToFrame(frame: CGRect, completion:() -> Void) {
func animate() {
self.dropDownView.frame = frame
}
func animationDidComplete(completed : Bool) {
self.isAnimating = false
if (completed) {
completion()
}
}
if (!self.isAnimating) {
self.isAnimating = true
UIView.animateWithDuration(0.5, delay: 0.0, options: .CurveEaseInOut, animations: animate, completion: animationDidComplete)
}
}
(我现在可以访问 Xcode,因此可能存在一些拼写错误。请根据需要进行更正)
关于ios - Swift 中的下拉动画 - 完成 block 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31413070/