UIView animateWithDuration 显示错误
UIView animateWithDuration shows error
我已经在 Objective-c 中成功实现了 UIView animateWithDuration 但是当我尝试在 Swift 中实现它时它不起作用并给出错误
无法使用
类型的参数列表调用 animateWithDuration
我的Objective-C代码是:
self.bottomConstraint.constant = 0;
[self.picker setNeedsUpdateConstraints];
[UIView animateWithDuration:0.3f animations:^{
[self.view layoutIfNeeded];
}];
我想在 swift 中转换相同的代码。如何转换?
试试这个:
UIView.animate(withDuration: 0.3) { () -> Void in
self.view.layoutIfNeeded()
return
}
这里的关键是:动画关闭应该return Void
所以明确return
应该可以解决你的问题。
试试这个,
UIView.animateWithDuration(0.3, animations: {
self.view.layoutIfNeeded()
})
Swift 5
:
UIView.animate(withDuration: 0.3, animations: {
self.view.layoutIfNeeded()
})
我已经在 Objective-c 中成功实现了 UIView animateWithDuration 但是当我尝试在 Swift 中实现它时它不起作用并给出错误 无法使用
类型的参数列表调用 animateWithDuration我的Objective-C代码是:
self.bottomConstraint.constant = 0;
[self.picker setNeedsUpdateConstraints];
[UIView animateWithDuration:0.3f animations:^{
[self.view layoutIfNeeded];
}];
我想在 swift 中转换相同的代码。如何转换?
试试这个:
UIView.animate(withDuration: 0.3) { () -> Void in
self.view.layoutIfNeeded()
return
}
这里的关键是:动画关闭应该return Void
所以明确return
应该可以解决你的问题。
试试这个,
UIView.animateWithDuration(0.3, animations: {
self.view.layoutIfNeeded()
})
Swift 5
:
UIView.animate(withDuration: 0.3, animations: {
self.view.layoutIfNeeded()
})