UIScrollView不使用autolayout約束我在后面有一個(gè)滾動(dòng)視圖和一個(gè)圖像視圖,我正在用nib填充它。我用的是自動(dòng)收費(fèi)表。在這兩個(gè)視圖中,我都有一個(gè)底部空間到SuperView,還有一個(gè)到SuperView的頂部空間。圖像視圖實(shí)現(xiàn)了我想要它做的事情。對于iPhone 5,它是我想要的地方。而對于其他iPhone,它保持在屏幕底部上方,因此它的大小是正確的。滾動(dòng)視圖在iPhone 5上看起來是對的,但在其他手機(jī)上它沒有調(diào)整大小,所以它向下滾動(dòng)到應(yīng)用程序的視圖下方。我在日志中得到了這些信息: 2012-11-21 10:42:38.576 LCHApp[12604:907] Unable to simultaneously satisfy constraints.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) "<NSLayoutConstraint:0x1d8ea080 UIScrollView:0x1d8413b0.bottom == UIImageView:0x1d892110.bottom>","<NSAutoresizingMaskLayoutConstraint:0x1d8cca10 h=-&- v=-&- ScheduleViewNib:0x1d853630.height == UIScrollView:0x1d8413b0.height - 386>","<NSLayoutConstraint:0x1d8e5340 V:[UIImageView:0x1d892110]-(64)-| (Names: '|':ScheduleView:0x1d8efc30 )>","<NSAutoresizingMaskLayoutConstraint:0x1d8cf520 h=--& v=--& V:[ScheduleView:0x1d8efc30(480)]>","<NSLayoutConstraint:0x1d8eaed0 V:|-(45)-[UIScrollView:0x1d8413b0] (Names: '|':ScheduleView:0x1d8efc30 )>"
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1d8ea080 UIScrollView:0x1d8413b0.bottom == UIImageView:0x1d892110.bottom>我已經(jīng)試過了[self setTranslatesAutoresizingMaskIntoConstraints:YES];和[self.myScrollView setTranslatesAutoresizingMaskIntoConstraints:YES];從我所能看到的情況來看,這只是去掉了視圖中的所有約束。也不是我想要的。
3 回答

楊魅力
TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超6個(gè)贊
在使用自動(dòng)布局時(shí)非常重要:您必須將最后一個(gè)子視圖的右邊和/或底部釘在滾動(dòng)視圖的右側(cè)和/或底部。滾動(dòng)視圖就是這樣知道內(nèi)容大小的。例如:
[scrollView?addConstraint:[NSLayoutConstraint?constraintWithItem:lastSubView ?????????????????????????????????????????????????attribute:NSLayoutAttributeRight ?????????????????????????????????????????????????relatedBy:NSLayoutRelationEqual ????????????????????????????????????????????????????toItem:scrollView ?????????????????????????????????????????????????attribute:NSLayoutAttributeRight ????????????????????????????????????????????????multiplier:1.0 ??????????????????????????????????????????????????constant:0]];

慕斯王
TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超2個(gè)贊
為了使UIScrollview能夠很好地處理約束,我使用了以下方法這里..在這個(gè)答案中,我討論了如何獲得一個(gè)垂直滾動(dòng)視圖工作,也適用于設(shè)備旋轉(zhuǎn)。您可以調(diào)整使用的方法。水平方向滾動(dòng)視圖。對于在兩個(gè)方向滾動(dòng)的滾動(dòng)視圖,別添加尺寸匹配寬度約束技巧。但是其他的事情都是一樣的。
- 3 回答
- 0 關(guān)注
- 712 瀏覽
添加回答
舉報(bào)
0/150
提交
取消