UIView.animate - Swift 3 - 完成处理函数

37

我该如何在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)

顺带说一下:

由于互联网上没有任何有效的资源,现在学习Swift 3相当困难 :(


我还搜寻了整个文档,甚至没有提到"animate"这个词:

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


2
未来参考:在自动生成.animate(...)函数后,双击蓝色高亮的((Bool) -> Void)?编辑器占位符,匿名块的结构将会准备好 :) - emmics
1个回答

109

你可以像这样添加它:

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

非常感谢!!!他们的“建议”太难懂了,实际上不知道该写什么...缺乏文档和大量不起作用的Swift2.2代码让人感到非常沮丧:( - Chris Allinson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接