[英]UIView transitionWithView swift syntax
Can some help me with the syntax of the transitionWithView in swift.可以帮助我快速使用 transitionWithView 的语法吗? in objective-c I would use it like so:在objective-c中,我会像这样使用它:
[UIView transitionWithView:[ self view ] duration:0.325 options:UIViewAnimationOptionCurveEaseOut animations:
^{
// do the transition
}
completion:
^( BOOL finished ){
// cleanup after the transition
}];
However I can not get the completion handler to work.但是我无法让完成处理程序工作。 thanks谢谢
it would be like this in Swift 5.x :在Swift 5.x 中会是这样:
UIView.transition(with: self.view, duration: 0.325, options: .curveEaseInOut, animations: {
// animation
}) { finished in
// completion
}
I'd like to add to the accepted answer that you can pass multiple options into transitionWithView
by passing an array like so:我想添加到已接受的答案中,您可以通过传递如下数组将多个选项传递给transitionWithView
:
UIView.transition(with: status, duration: 0.33, options:
[.curveEaseOut, .transitionCurlDown], animations: {
//...animations
}, completion: {_ in
//....transition completion
delay(seconds: 2.0) {
}
})
UIView.transitionWithView(status, duration: 0.33, options:
[.CurveEaseOut, .TransitionCurlDown], animations: {
//...animations
}, completion: {_ in
//....transition completion
delay(seconds: 2.0) {
}
})
UIView.transitionWithView(status, duration: 0.33, options:
.CurveEaseOut | .TransitionCurlDown, animations: {
//...animations
}, completion: {_ in
//transition completion
delay(seconds: 2.0) {
}
})
and of course you can use the fully qualified syntax like this as well:当然,您也可以使用完全限定的语法,如下所示:
[UIViewAnimationOptions.CurveEaseOut, UIViewAnimationOptions.TransitionCurlDown]
UIView.transition(with: someview,
duration:0.6,
options:UIViewAnimationOptions.transitionFlipFromLeft,
animations: {
// do something
}, completion:{
finished in
// do something
})
the docs are a little tricky to find, but this should work: 文档有点难找,但这应该有效:
UIView.transitionWithView(self.view,
duration:0.325,
options: options:UIViewAnimationOptions.CurveEaseOut,
animations: {
…
},
completion: {
finished in
…
})
You could use a trailing closure if you wanted for the completion
handler, but I wouldn't in this case, it would be too messy/unclear.如果您想要completion
处理程序,您可以使用尾随闭包,但在这种情况下我不会,它会太混乱/不清楚。
But if you weren't going to pass an animations block, it would be borderline readable:但是如果你不打算传递一个动画块,它会是边缘可读的:
UIView.transitionWithView(self.view, duration:0.325, options: options:UIViewAnimationOptions.CurveEaseOut, animations: nil) {
finished in
…
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.