[英]Cannot get closure syntax to work in swift 4
I've tried every syntax variation that I can, but the completion handler always activates before the end of the animation. 我已经尝试了所有可能的语法变体,但是完成处理程序总是在动画结束之前激活。 I think I'm supposed to replace
Bool
with something else? 我认为我应该用其他东西代替
Bool
吗?
UIView.transition(with: swipeForPicturesIndicator,
duration: 1,
options: .curveEaseIn,
animations: {
self.swipeForPicturesIndicator.alpha = 0
},
completion: { (Bool) -> Void in
self.swipeForPicturesIndicator.isHidden = true
self.swipeForPicturesIndicator.alpha = 0.8
})
The Bool
value indicates wether the animation was finished when the completion block was called. Bool
值指示在调用完成块时动画是否结束。 If that value is false
it means your animation was interrupted. 如果该值为
false
则表示您的动画已中断。
You should use probably animate
instead of transition
您应该使用
animate
而不是transition
UIView.animate(withDuration: 1,
delay: 0,
options: .curveEaseIn,
animations: {
self.swipeForPicturesIndicator.alpha = 0
}) { (completed) in
/* Optionally check if animation finished */
self.swipeForPicturesIndicator.isHidden = true
self.swipeForPicturesIndicator.alpha = 0.8
}
Try this 尝试这个
self.swipeForPicturesIndicator.alpha = 0
UIView.transition(with: swipeForPicturesIndicator,
duration: 1,
options: .curveEaseIn,
animations: {
self.swipeForPicturesIndicator.alpha = 0.8
},
completion: nil)
You may want to use animate instead of transition: 您可能要使用动画而不是过渡:
UIView.animate(withDuration: 1, delay: 0, options: .curveEaseIn, animations: {
self.swipeForPicturesIndicator.alpha = 0
}) { (success) in
self.swipeForPicturesIndicator.isHidden = true
self.swipeForPicturesIndicator.alpha = 0.8
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.