2016-09-25 44 views
8

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

我想设置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) 

在传:

这是非常不可能的学习斯威夫特3个大气压,由于互联网上的工作NOTHING :(


我也搜遍了整个文件,甚至提到单词 “动画”,但没有找到任何东西:

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

+1

对于未来:后自动生成.animate(...)函数,双击蓝色突出显示的((Bool) - > Void)?编辑器占位符和匿名块的结构将准备:) – Muli

回答

49

你加入这样的:

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

感谢一堆!他们的“建议”太神秘了,无法理解实际上写什么...以及缺少文档,以及压倒性数量的非工作swift2.2-代码是相当令人沮丧的:( –

+0

动画是伟大的,但我怎么能相同按钮单击时按下布局? – pmb

-2

写类似下面的代码:

UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: { 

// code 

}) 
+0

此答案不包含完成块,这是问题的要求。 – frakman1