ios UIView.animate - Swift 3 - 完成

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39682128/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 10:21:10  来源:igfitidea点击:

UIView.animate - Swift 3 - completion

iosswift3uiviewanimation

提问by Chris Allinson

How do I do a simple completion block in Swift 3?

如何在 Swift 3 中做一个简单的完成块?

I want to set self.isOpen = truein the completion of the animation:

我想self.isOpen = true在完成动画时设置:

            UIView.animate(withDuration: 0.25, delay: 0.0, options: [], animations: {
                self.isOpen = true
                self.drawerView?.frame = CGRect(x: 0, y: 0, width: (self.drawerView?.frame.size.width)!, height: (self.drawerView?.frame.size.height)!)
                self.contentView?.frame = CGRect(x: 200, y: 0, width: (self.contentView?.frame.size.width)!, height: (self.contentView?.frame.size.height)!)
            }, completion: nil)


In passing:

顺便:

It's pretty impossible to learn Swift 3 atm due to NOTHING on the internet working :(

由于互联网上没有任何工作,学习 Swift 3 atm 几乎是不可能的:(



I've also searched this entire document for even a mention of the word "animate" and could not find anything:

我还搜索了整个文档,甚至没有提到“动画”一词,但找不到任何内容:

https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/index.html#//apple_ref/doc/uid/TP40014097-CH3-ID0

https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/index.html#//apple_ref/doc/uid/TP40014097-CH3-ID0

回答by rmaddy

You add it like this:

你像这样添加它:

UIView.animate(withDuration: 0.25, delay: 0.0, options: [], animations: {
    self.drawerView?.frame = CGRect(x: 0, y: 0, width: (self.drawerView?.frame.size.width)!, height: (self.drawerView?.frame.size.height)!)
    self.contentView?.frame = CGRect(x: 200, y: 0, width: (self.contentView?.frame.size.width)!, height: (self.contentView?.frame.size.height)!)
}, completion: { (finished: Bool) in
    self.isOpen = true
})