UIView transitionWithView swift语法
有些人可以用swift的transitionWithView的语法来帮助我。 在Objective-C中,我会像这样使用它:
[UIView transitionWithView:[ self view ] duration:0.325 options:UIViewAnimationOptionCurveEaseOut animations: ^{ // do the transition } completion: ^( BOOL finished ){ // cleanup after the transition }];
但是我不能让完成处理程序工作。 谢谢
在Swift中会是这样的:
UIView.transitionWithView(self.view, duration: 0.325, options: UIViewAnimationOptions.CurveEaseInOut, animations: { // animation }, completion: { (finished: Bool) -> () in // completion })
我想添加到接受的答案,您可以传递多个选项到transitionWithView
传递一个数组,如下所示:
Swift 2.0
UIView.transitionWithView(status, duration: 0.33, options: [.CurveEaseOut, .TransitionCurlDown], animations: { //...animations }, completion: {_ in //....transition completion delay(seconds: 2.0) { } })
Swift 1.2
UIView.transitionWithView(status, duration: 0.33, options: .CurveEaseOut | .TransitionCurlDown, animations: { //...animations }, completion: {_ in //transition completion delay(seconds: 2.0) { } })
当然你也可以使用这种完全合格的语法:
[UIViewAnimationOptions.CurveEaseOut, UIViewAnimationOptions.TransitionCurlDown]
Swift 3
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
处理程序,你可以使用尾随闭包 ,但是在这种情况下我不会太杂乱/不清楚。
但是如果你不打算通过一个animation块,它将是边界可读的:
UIView.transitionWithView(self.view, duration:0.325, options: options:UIViewAnimationOptions.CurveEaseOut, animations: nil) { finished in … }