animateWithDuration:动画:完成:在斯威夫特
问题描述:
在Objective-C我的动画位将是这个样子:animateWithDuration:动画:完成:在斯威夫特
[UIView animateWithDuration:0.5 animations:^{
[[[_storedCells lastObject] topLayerView] setFrame:CGRectMake(0, 0, swipeableCell.bounds.size.width, swipeableCell.bounds.size.height)];
} completion:^(BOOL finished) {
[_storedCells removeLastObject];
}];
如果我翻译成雨燕应该是这个样子:
UIView.animateWithDuration(0.5, animations: {
self.storedCells[1].topLayerView.frame = CGRectMake(0, 0, cell.bounds.size.width, cell.bounds.size.height)
}, completion: { (finished: Bool) in
//self.storedCells.removeAtIndex(1)
})
它抱怨注释行。我收到的错误是:Could not find an overload for 'animateWithDuration' that accepts the supplied arguments
我知道完成闭包需要一个布尔值并返回一个void,但是我应该能够写出一些与bool无关的东西....对吧?
任何帮助表示赞赏。
编辑:这里是我声明我正在使用的功能数组:
var storedCells = SwipeableCell[]()
数组,需要SwipeableCell对象。
答
这是一个很好的,棘手的!
的问题是在你完成块...
答:我会通过改写它像这样开始:(!不是最终的答案,但对我们的方式存在)
{ _ in self.storedCells.removeAtIndex(1) }
(_
代替“已完成”Bool,向读者指示其值未在块中使用 - 您也可以考虑根据需要添加捕获列表以防止强参考周期)
B.你写的闭包有一个返回类型,当它不应该!这一切都归功于雨燕的方便的功能“从单一的表达关闭隐含的回报” - 要返回的表达,这是给定的指标
(封闭的参数为completion
类型应该在元素的结果((布尔) - >无效))
这可以解决像这样:
{ _ in self.storedCells.removeAtIndex(1); return() }
你能告诉self.storedCells'的'的声明和分配。 –
@ 0x7fffffff我更新了我的回答 –