【发布时间】:2014-07-29 08:54:35
【问题描述】:
我正在使用 UIView 动画向上/向下移动视图(使用自动布局)。
动画适用于模拟器,但不适用于实际设备。可能是什么问题呢?做动画的代码在这里
[self layoutIfNeeded];
[UIView animateWithDuration:.5 animations:^{
self.animationConstraint.constant = -190;
[self bringSubviewToFront:self.containerView];
[self.containerView layoutIfNeeded];
}];
我检查了内存使用情况,但在制作动画时它没有超过 2%。
【问题讨论】:
-
不会 [self layoutIfNeeded];已经将 UI 元素更新到没有动画的新位置,因此为什么您在设备上看不到任何内容?如果你注释掉那一行会发生什么?
-
好吧,动画没有发生。但是位置发生了变化,就像它只是跳到了位置一样。
-
我相信它的工作方式是将constraint.constant更新放在UIView动画块之外,并将layoutIfNeeded放在动画块内。
-
已解决。我必须重新布局父视图,而不是约束附加到的视图。所以代替 [self.containerView layoutIfNeeded]; , [selflayoutIfNeeded];成功了。非常感谢:)
标签: ios objective-c animation autolayout uiviewanimation