- Masonry布局定位約束沖突
視圖布局添加約束的時(shí)候泛鸟,有的時(shí)候會(huì)報(bào)一對(duì)約束沖突:
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.
"<MASLayoutConstraint:0x28244a340 UILabel:0x13b80b190.top == 邦邦。该编。。
有的時(shí)候,通過(guò)控制臺(tái)打印,能夠大致看出哪個(gè)子控件出現(xiàn)了問(wèn)題,但是當(dāng)視圖控件和層級(jí)比較多時(shí)刃唤,就難以分辨。
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
這個(gè)時(shí)候我們可以通過(guò)添加斷點(diǎn)的方式白群,在查看定位約束沖突尚胞。步驟:
添加Symbolic Breakpoint
在symbol欄添加 UIViewAlertForUnsatisfiableConstraints
在Action欄 添加po [[UIWindow keyWindow] _autolayoutTrace]
此時(shí)重新運(yùn)行工程,打開(kāi)出現(xiàn)約束沖突的頁(yè)面帜慢,控制臺(tái)就會(huì)打印出視圖各層級(jí)以及地址笼裳,通過(guò)約束沖突的控件地址對(duì)比,就能找到相應(yīng)的視圖控件粱玲。
NSAutoresizingMaskLayoutConstraint 約束導(dǎo)致的約束沖突:self.translatesAutoresizingMaskIntoConstraints = NO;
- Masonry約束優(yōu)先級(jí)的設(shè)置
開(kāi)發(fā)的時(shí)候躬柬,有的時(shí)候會(huì)遇到一行出現(xiàn)兩種文本展示框,約束添加不好抽减,就會(huì)達(dá)不到想要的效果允青。
通過(guò)以上代碼,可以設(shè)置在同一行的文本框優(yōu)先展示哪一個(gè)文本框的內(nèi)容卵沉。然后可以根據(jù)現(xiàn)有項(xiàng)目的需要颠锉,來(lái)進(jìn)行設(shè)置法牲。
效果如下: