私はビューに対してアニメーションを実行する関数を持っています。アニメーションが完了した後に呼び出されるこの関数の補完ハンドラを実装したいと思います。 ViewControllerで完了ハンドラに関数を渡す
... HudViewクラスで
hudView.hide(animated: true, myCompletionHandler: {
// Animation is complete
})
...
func hide(animated: Bool, myCompletionHandler:() -> Void) {
if animated {
transform = CGAffineTransform(scaleX: 0.7, y: 0.7)
UIView.animate(withDuration: 0.3, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.5, options: [], animations: {
self.alpha = 0
self.transform = CGAffineTransform.identity
}, completion: nil) // I want to run 'myCompletionHandler' in this completion handler
}
}
、私は多くのことを試してみたが、正しい構文を見つけることができません。
}, completion: myCompletionHandler)
Passing non-escaping parameter 'myCompletionHandler' to function expecting an @escaping closure
}, completion: myCompletionHandler())
迅速な初心者として
Cannot convert value of type 'Void' to expected argument type '((Bool) -> Void)?'
}, completion: { myCompletionHandler() })
Closure use of non-escaping parameter 'myCompletionHandler' may allow it to escape
これらのエラーメッセージは、私には非常に多くを意味するものではありませんし、私はこれを行うには正しい方法のいずれかの例を見つけるように見える傾けます。
myCompletionHandler
を.animate
完了ハンドラに渡す正しい方法は何ですか?
Davidありがとう。それは素晴らしい作品です。 – Turnip