SnapKit / Masonry

Harness the power of AutoLayout NSLayoutConstraints with a simplified, chainable and expressive syntax. Supports iOS and OSX Auto Layout
MIT License
18.05k stars 3.14k forks source link

width怎么往某一方向展开 #479

Open OCer opened 6 years ago

OCer commented 6 years ago

New Issue Checklist

🚫 If this template is not filled out your issue will be closed with no comment. 🚫

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)。

Eflet commented 6 years ago

再限定下left啊, [make left].mas_equalTo

KelaKing commented 6 years ago

如果约束都正确的话调 [self.superview layoutIfNeed] 而不是 [self layoutIfNeed]

OCer commented 6 years ago

怎么说? 如果self是父控件,那要刷新添加到它上面的view,不应该是 [self layoutIfNeed]?? @KelaKing

KelaKing commented 6 years ago

如果只调 [self layoutIfNeed], 布局引擎会计算width变化,但对父视图的约束没有计算(比如说与父视图左对齐),导致动画 block 中 frame 计算不准确 @OCer

OCer commented 6 years ago

我父控件的大小是已经定了的 不再改变

zwind007 commented 6 years ago

I have came across the same problem.

zwind007 commented 6 years ago

问题已经解决,关键在这句 [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];
}];