- UIScrollView在Xib中會(huì)報(bào)Scroll View has ambiguous scrollable content height / width答姥,原因是UIScrollView除了設(shè)置frame外,還需要contentsize谚咬。
常規(guī)都是在UIScrollView內(nèi)放一個(gè)ContainerView鹦付,在ContainerView內(nèi)放置自己的控件。
1.拖入ScrollView择卦,對(duì)View拖線敲长,設(shè)置4邊約束
2.給ScrollView增加一個(gè)子ContainerView,ContainerView對(duì)著ScrollView拖線秉继,設(shè)置4邊約束
3.ContainerView對(duì)著控制器View拖線祈噪,(豎向滾動(dòng)的話:設(shè)置等寬,給一個(gè)fixed的高度)(橫向滾動(dòng)的話:設(shè)置等高尚辑,給一個(gè)fixed的寬度)(也可以都設(shè)置固定高度辑鲤,反正就是給ContainerView設(shè)置個(gè)寬和高的約束)
4.如果是xcode11(11的bug,感謝阿三哥8懿纭T氯臁!)澈蝙,修改之前的拖線約束的constant = 0
5.再次吐槽下xcode11.2吓坚,就是個(gè)垃圾,只要xib拖過(guò)UITextView灯荧,跑項(xiàng)目就會(huì)報(bào)錯(cuò)Could not instantiate class named _UITextLayoutView because no class named _UITextLayoutView was found礁击,我已經(jīng)回退到Xcode11.1版本了
6.關(guān)于這個(gè)xcode11.2的XIB bug,網(wǎng)上有處理方法逗载,可以在appdidFinishLaunch方法中手動(dòng)強(qiáng)行動(dòng)態(tài)加載這個(gè)類哆窿,核心代碼如下
const char *className = "_UITextLayoutView";
Class class = objc_getClass(className);
if (class == nil) {
class = objc_allocateClassPair([UIView class], className, 0);
objc_registerClassPair(class);
}