【发布时间】:2018-06-10 00:58:26
【问题描述】:
我有一个动态宽度UILabel(为可见性着色为石灰绿色),它对其邻居(绿色和红色视图)具有固定的前导和尾随约束。我希望这张桌子在它的一个邻居被移动时调整它的宽度(圆形的红色/绿色视图)。但是,由于我的标签的宽度在没有动画的情况下“跳转”到其新值,因此我对这种更改的动画有疑问。对于我的右对齐标签,这意味着文本本身也会跳跃。
我正在为红色/绿色视图的移动设置动画,如下所示:
- (void)show {
self.edgeConstraint.constant = 0;
[UIView animateWithDuration:0.25 animations:^{
[self.contentView layoutIfNeeded];
}];
}
- (void)hide {
self.edgeConstraint.constant = -100;
[UIView animateWithDuration:0.25 animations:^{
[self.contentView layoutIfNeeded];
}];
}
【问题讨论】:
-
在设置约束之前调用
layoutIfNeeded。然后在动画块内调用layoutIfNeeded(你已经在做这个了)。看看这是否有效。 -
这个 gif 是你想要的还是问题???
标签: ios uiview autolayout uilabel uiviewanimation