我使用此消息将客户视图动画化到设备屏幕的下边缘。我已经连接了布局约束并将初始常量设置为 -60。当值设置为 0 时,我希望视图动画到顶部。但不幸的是,预期的功能不起作用。即使调用该方法,当界面方向更改时,视图也希望向上。我正在使用Xcode 6.4和iOS 8作为基本sdk。任何帮助将不胜感激。
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];
}];
}
每当要对约束更改进行动画处理时,都必须定义动画块中的线条。
所以你的代码会变成这样,
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];
}];
}