Masonry
Masonry copied to clipboard
width怎么往某一方向展开
New Issue Checklist
🚫 If this template is not filled out your issue will be closed with no comment. 🚫
- [ √] I have looked at the Documentation
- [ √] I have filled out this issue template.
Issue Info
Info | Value |
---|---|
Platform | ios |
Platform Version | 10.0 |
Masonry Version | 1.0 |
Integration Method | manually |
Issue Description
我用mansory做动画,很简单,就改变宽度 [self mas_updateConstraints:^(MASConstraintMaker *make) { [make width].mas_equalTo(BLSelectableButtonWidth * self.items.count); }];
但是,这个动画并不理想,我想要的是x不变,width往某一方向展开。 但事实上是,width在中心点同时往2边展开,这就导致了在做动画的时候,x出现偏移的视觉效果(因为约束的关系,事实上在做动画前width已经确定了,而width是2边展开的,为了x不变,所以view在调整x)。
再限定下left啊, [make left].mas_equalTo
如果约束都正确的话调 [self.superview layoutIfNeed] 而不是 [self layoutIfNeed]
怎么说? 如果self是父控件,那要刷新添加到它上面的view,不应该是 [self layoutIfNeed]?? @KelaKing
如果只调 [self layoutIfNeed]
, 布局引擎会计算width变化,但对父视图的约束没有计算(比如说与父视图左对齐),导致动画 block 中 frame 计算不准确
@OCer
我父控件的大小是已经定了的 不再改变
I have came across the same problem.
问题已经解决,关键在这句
[self.progressBarView.superview.superview layoutIfNeeded];
[self.progressWidthConstraint uninstall];
[self.progressBarView mas_makeConstraints:^(MASConstraintMaker *make) {
self.progressWidthConstraint = make.width.equalTo(self.progressBarTraceView).multipliedBy(self.progress);
}];
[UIView animateWithDuration:1.0 animations:^{
[self.progressBarView.superview.superview layoutIfNeeded];
}];