從代碼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
啊