Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView.animate - Swift 3 - completion

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

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

            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 :(


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

like image 704
Chris Allinson Avatar asked Sep 25 '16 00:09

Chris Allinson


1 Answers

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 }) 
like image 123
rmaddy Avatar answered Sep 23 '22 19:09

rmaddy