Ios UIView animateWithDuration显示错误
我已经在Objective-c中成功地实现了UIView animateWithDuration,但当我尝试在Swift中实现它时,它不起作用,并给出错误信息 无法使用类型为的参数列表调用animateWithDuration 我的目标C代码是:Ios UIView animateWithDuration显示错误,ios,swift,uiviewanimation,Ios,Swift,Uiviewanimation,我已经在Objective-c中成功地实现了UIView animateWithDuration,但当我尝试在Swift中实现它时,它不起作用,并给出错误信息 无法使用类型为的参数列表调用animateWithDuration 我的目标C代码是: self.bottomConstraint.constant = 0; [self.picker setNeedsUpdateConstraints]; [UIView animateWithDuration:0.3f animatio
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
}
关键是:动画闭包应该返回Void,所以显式返回应该可以解决您的问题。试试这个
UIView.animateWithDuration(0.3, animations: {
self.view.layoutIfNeeded()
})
Swift 5:
您能否显示您尝试过的swift代码编辑您的问题以显示给您带来问题的swift代码,否则此问题将被关闭。”寻求调试帮助的问题此代码为什么不起作用?必须包括所需的行为、特定的问题或错误以及在问题本身中重现这些问题所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:如何创建一个最小、完整且可验证的示例。”
UIView.animate(withDuration: 0.3, animations: {
self.view.layoutIfNeeded()
})