简体   繁体   English

UIView.animate - Swift 3 - 完成

[英]UIView.animate - Swift 3 - completion

How do I do a simple completion block in Swift 3? 如何在Swift 3中执行简单的完成块?

I want to set self.isOpen = true in 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 :( 由于互联网上的NOTHING工作,学习Swift 3 atm是不可能的:(


I've also searched this entire document for even a mention of the word "animate" and could not find anything: 我还搜索了整个文档,甚至提到了“animate”这个词,但找不到任何东西:

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

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
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM