我正在尝试从 Objective-C 重写为 Swift,我无法理解语法或理解文档
这是我在 Objective-C 中编写的一个简化示例:
[UIView animateWithDuration:10.0 animations:^{self.navigationController.toolbar.frame = CGRectMake(0,10,0,10);}];
如何在 Swift 中编写此代码?
这是自动完成的模板:
UIView.animateWithDuration(duration: NSTimeInterval, animations: (() -> Void))
最佳答案
这是 swift 闭包格式:
{(parameter:type, parameter: type, ...) -> returntype in
//do stuff
}
这是你应该做的:
//The animation closure will take no parameters and return void (nothing).
UIView.animateWithDuration(duration: NSTimeInterval, animations: {() -> Void in
//Animate anything.
})
这是 documentation关闭。
关于ios - Swift 中 block 的语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24038713/