【发布时间】:2017-03-27 18:52:58
【问题描述】:
【问题讨论】:
-
只需创建一个您想要更改的约束的出口,就像创建 UIButton 或 UILabel 的出口一样。
标签: ios objective-c xcode-storyboard
【问题讨论】:
标签: ios objective-c xcode-storyboard
然后在代码中设置约束的常量值:
labelWidthConstraint.constant = newValue
如果你想要动画,你可以这样做:
labelWidthConstraint.constant = newValue
UIView.animate(withDuration: 0.3, animations: {
self.view.layoutIfNeeded()
})
self.labelWidthConstraint.constant = newValue;
[UIView animateWithDuration:0.3 animations:^{
[self.view layoutIfNeeded];
}];
【讨论】:
layoutSubviews()(请参阅文档)。请改用layoutIfNeeded()。
layoutIfNeeded方法。