[英]UIView transitionWithView swift syntax
可以幫助我快速使用 transitionWithView 的語法嗎? 在objective-c中,我會像這樣使用它:
[UIView transitionWithView:[ self view ] duration:0.325 options:UIViewAnimationOptionCurveEaseOut animations:
^{
// do the transition
}
completion:
^( BOOL finished ){
// cleanup after the transition
}];
但是我無法讓完成處理程序工作。 謝謝
在Swift 5.x 中會是這樣:
UIView.transition(with: self.view, duration: 0.325, options: .curveEaseInOut, animations: {
// animation
}) { finished in
// completion
}
我想添加到已接受的答案中,您可以通過傳遞如下數組將多個選項傳遞給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) {
}
})
當然,您也可以使用完全限定的語法,如下所示:
[UIViewAnimationOptions.CurveEaseOut, UIViewAnimationOptions.TransitionCurlDown]
UIView.transition(with: someview,
duration:0.6,
options:UIViewAnimationOptions.transitionFlipFromLeft,
animations: {
// do something
}, completion:{
finished in
// do something
})
文檔有點難找,但這應該有效:
UIView.transitionWithView(self.view,
duration:0.325,
options: options:UIViewAnimationOptions.CurveEaseOut,
animations: {
…
},
completion: {
finished in
…
})
如果您想要completion
處理程序,您可以使用尾隨閉包,但在這種情況下我不會,它會太混亂/不清楚。
但是如果你不打算傳遞一個動畫塊,它會是邊緣可讀的:
UIView.transitionWithView(self.view, duration:0.325, options: options:UIViewAnimationOptions.CurveEaseOut, animations: nil) {
finished in
…
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.