有些时候我们在xib、storyboard中布置好约束后,想在某些时候使用代码改变约束,我习惯用masonry,可能会出现的问题是:
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
这就是出现了约束冲突,在此语句下,系统会告知约束冲突的地方。怎么解决?
像我们使用xib在view上布局一个button,xib上把约束弄好后,以button上边距离父视图上边举例,想在某个时候不动xib约束,然后又可用代码控制,masonry可这样写
[self.button mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_top).offset(3);
}];
然后xib中要把button上边距离父视图上边的约束的优先级不使用默认1000了,使用750,即降低优先级,这样就行了,storyboard同。
屏幕快照 2019-03-13 15.52.45.png