UIScrollView的storyboard問題和導(dǎo)航偏移問題

從代碼push到storyboard上的一個VC

在storyboard上給VC設(shè)置一個storyboard ID
然后

    UIStoryboard *novelSB = [UIStoryboard storyboardWithName:@"NewNovel" bundle:[NSBundle mainBundle]];
    NewNovelViewController *novelVC = [novelSB instantiateViewControllerWithIdentifier:@"NewNovelViewController"];
    [self.navigationController pushViewController:novelVC animated:YES];

storyboard上創(chuàng)建一個scrollView(Xcode8)

1.點擊VC的show the attributes inspector,將size設(shè)置成Freeform;
2.點擊VC的show the size inspector,將高度設(shè)置成大約想滾動的高度,比如999;
3.在VC的view上添加scrollView,設(shè)置約束,比如scrollView[Top, Bottom, Leading, Trailing] = view[Top, Bottom, Leading, Trailing];
4.往scrollView上添加一個view作為contentView,設(shè)置view的約束(需要設(shè)置Top, Bottom, Leading, Trailing,Width,Height),Top, Bottom, Leading, Trailing,Width與scrollView相同即可,height設(shè)置成想要的,比如999;
5.往contentView上添加UI即可。

scrollView的導(dǎo)航偏移問題

遇到含導(dǎo)航欄的ViewController,其第一個子試圖是UIScrollView會自動產(chǎn)生64像素偏移。 找了哈資料發(fā)現(xiàn)可以通過設(shè)置viewcontroller的self.automaticallyAdjustsScrollViewInsets = false解決了。

另外一個辦法就去Storyboard上將ViewController 的Under Top Bar勾去掉也可以解決

參考https://www.swiftmi.com/topic/329.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容