UIView动画布局无法正常工作

时间:2016-02-15 07:34:50

标签: ios objective-c uiviewanimation

我正在使用此消息将客户视图设置为设备屏幕下边缘的动画。我已连接布局约束并将初始常量设置为-60。当值设置为0时,我希望视图以动画显示为顶部。但不幸的是,预期的功能无法正常工作。即使调用该方法,也希望在界面方向改变时查看。我使用Xcode 6.4和iOS 8作为基础sdks。任何帮助将不胜感激。

if (alertVisible)
{
     self.alertViewVerticalConstraint.constant = 0;
    [UIView animateWithDuration:0.25 animations: ^{
        [self.view bringSubviewToFront:self.alertView];
        self.alertView.alpha = 0.5;

        [self.alertView layoutIfNeeded];
    }];
}
else
{
     self.alertViewVerticalConstraint.constant = -60;
    [UIView animateWithDuration:0.25 animations: ^{
        self.alertView.alpha = 0.0;

        [self.alertView layoutIfNeeded];
    }];
}

1 个答案:

答案 0 :(得分:2)

每当您想要为约束更改设置动画时,您必须在动画块中定义该行。

所以你的代码会变成这样的,

if (alertVisible)
{
[UIView animateWithDuration:0.25 animations: ^{
    self.alertViewVerticalConstraint.constant = 0;

    [self.view bringSubviewToFront:self.alertView];
    self.alertView.alpha = 0.5;

    [self.view layoutIfNeeded];
 }];
}
else
{
   [UIView animateWithDuration:0.25 animations: ^{
       self.alertViewVerticalConstraint.constant = -60;

       self.alertView.alpha = 0.0;

      [self.view layoutIfNeeded];
}];
}
相关问题