xcode UIView.beginAnimations 上下文 - Swift
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24188858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UIView.beginAnimations context - Swift
提问by Team6Labs
I'm having trouble getting a UIView (UIButton) to animate in Swift. Can anyone help? Here is my code. I'm mainly having trouble with the method [UIView.beginAnimations]. It requires me to pass in a String and a CMutableVoidPointer. This currently crashes. Thanks
我无法在 Swift 中获取 UIView (UIButton) 动画。任何人都可以帮忙吗?这是我的代码。我的主要问题是 [UIView.beginAnimations] 方法。它需要我传入一个字符串和一个 CMutableVoidPointer。这目前崩溃了。谢谢
var newCenter:CGPoint = CGPointMake(playAgainButton.center.x, playAgainButton.center.y + 200)
[UIView.beginAnimations(nil, context: nil)]
[UIView.setAnimationDuration(1.0)]
playAgainButton.center = newCenter
[UIView.commitAnimations]
回答by PREMKUMAR
Change code below. It must work in Swift
更改下面的代码。它必须在 Swift 中工作
var newCenter:CGPoint = CGPointMake(playAgainButton.center.x, playAgainButton.center.y + 200)
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(1.0)
playAgainButton.center=newCenter
UIView.commitAnimations()
回答by Mick MacCallum
You shouldn't be using that method to do view animations. Apple has recommended doing block based UIView animations since iOS 4. The block base equivalent that you want looks like this in Swift:
您不应该使用该方法来查看动画。从 iOS 4 开始,Apple 已经推荐使用基于块的 UIView 动画。在 Swift 中,你想要的块基等效看起来像这样:
UIView.animateWithDuration(1.0) {
playAgainButton.center = CGPointMake(playAgainButton.center.x, playAgainButton.center.y + 200)
}
回答by holex
I recommend to use block-based version instead:
我建议改用基于块的版本:
UIView.animate(withDuration: 1.0) {
playAgainButton.center.y + 200.0)
}