UIView animateWithDuration显示错误

时间:2015-09-26 12:17:33

标签: ios swift uiviewanimation

我已经在Objective-c中成功实现了UIView animateWithDuration但是当我尝试在Swift中实现它时它不起作用并且给出错误 无法使用类型

的参数列表调用animateWithDuration

我的Objective-C代码是:

self.bottomConstraint.constant = 0;
    [self.picker setNeedsUpdateConstraints];
    [UIView animateWithDuration:0.3f animations:^{
        [self.view layoutIfNeeded];
    }];

我想在swift中转换相同的代码。我怎么转换?

2 个答案:

答案 0 :(得分:0)

试试这个:

UIView.animateWithDuration(0.3) { () -> Void in
    self.view.layoutIfNeeded()
    return
}

此处的密钥:动画关闭应返回Void,因此明确的return应解决您的问题。

答案 1 :(得分:0)

试试这个,

UIView.animateWithDuration(0.3, animations: {
    self.view.layoutIfNeeded()
})