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()
。 - clemenslayoutIfNeeded
方法即可。 - Sunil Chauhan