fileprivate func hideViewWithAnimation() {
UIView.animate(withDuration: 0.3, animations: { [weak self]
if self == nil {
return
}
self!.view.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0)
self!.constraintContainerViewBottom.constant = -Constants.screenHeight()
self!.constraintContainerViewTop.constant = Constants.screenHeight()
self!.view.layoutIfNeeded()
}, completion: { (isCompleted) in
self.navigationController?.dismiss(animated: false, completion: nil)
})
}
显示 [weak self] 要求使用 ',' 分隔的错误。我做错了什么
最佳答案
正如Tj3n所说,当你使用[weak self]
语法时,你需要in
关键字,例如
UIView.animate(withDuration: 0.3) { [weak self] in
self?.view.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0)
...
}
但是你根本不需要在动画 block 中使用[weak self]
,因为动画 block 在动画片。没有强引用循环可以打破。所以我建议完全删除 [weak self]
。
而且,如果您想知道,您也不必担心 completion
block 中的强引用,因为当 View 被关闭时,正在进行的动画被取消并且 completion
block 被立即调用, bool 参数为 false
。
关于ios - [weak self] 给出以下代码 : Expected ',' Separator 的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39570092/