static func animate(_ duration: TimeInterval,
animations: (() -> Void)!,
delay: TimeInterval = 0,
options: UIViewAnimationOptions = [],
withComplection completion: (() -> Void)! = {}) {
UIView.animate(
withDuration: duration,
delay: delay,
options: options,
animations: {
animations()
}, completion: { finished in
completion()
})
}
Run Code Online (Sandbox Code Playgroud)
在我的swift文件中使用上面的类并创建如下所示的函数
SPAnimation.animate(durationScalingRootView,
animations: {
rootViewController.view.transform = CGAffineTransform.identity
},
delay: delayScalingRootView,
options: UIViewAnimationOptions.curveEaseOut,
withComplection: {
finished in
//rootViewController.view.layer.mask = nil
})
Run Code Online (Sandbox Code Playgroud)
得到此错误
上下文闭包类型'() - > Void'需要0个参数,但在闭包体中使用了1
问题出在这里:
withComplection: {
finished in
//rootViewController.view.layer.mask = nil
}
Run Code Online (Sandbox Code Playgroud)
如果查看方法声明,则完成处理程序的类型为(() -> Void)!.它不需要任何论据.你上面的闭包有一个论点 - finished.结果,发生错误.
finished从闭包中删除参数:
withComplection: {
//rootViewController.view.layer.mask = nil
}
Run Code Online (Sandbox Code Playgroud)
或者您编辑您的animate方法以接受带有一个参数的闭包:
static func animate(_ duration: TimeInterval,
animations: (() -> Void)!,
delay: TimeInterval = 0,
options: UIViewAnimationOptions = [],
withComplection completion: ((Bool) -> Void)? = nil) {
UIView.animate(
withDuration: duration,
delay: delay,
options: options,
animations: {
animations()
}, completion: { finished in
completion?(finished)
})
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5560 次 |
| 最近记录: |