UIView 动画布局如果需要不起作用 [英] UIView animation layoutIfneeded not working
问题描述
我正在使用此消息将客户视图动画化到设备屏幕的下边缘.我已经连接了布局约束并将初始常量设置为 -60.当该值设置为 0 时,我希望视图动画到顶部.但不幸的是,预期的功能不起作用.即使调用了该方法,当界面方向发生变化时,该视图也有望打开.我使用 Xcode 6.4 和 iOS 8 作为基础 sdks.任何帮助将不胜感激.
I am using this message to animate a customer view to the lower edge of the device screen. I've connected the layout constraint and set initial constant as -60. When the value is set to 0, I expect the view to animate to top. But unfortunately the expected functionality is not working. Even the method is called, the view is hoped up when interface orientation changes. I am using Xcode 6.4 and iOS 8 as base sdks. Any help will be appreciated.
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];
}];
}
推荐答案
每当您想要为约束更改设置动画时,您都必须在动画块内定义线.
Whenever you want to animate the constraint changes, you have to defines the line within the animation block.
所以你的代码会变成这样,
So your code will become something like this,
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];
}];
}
这篇关于UIView 动画布局如果需要不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!