从代码push到storyboard上的一个VC
在storyboard上给VC设置一个storyboard ID
然后
UIStoryboard *novelSB = [UIStoryboard storyboardWithName:@"NewNovel" bundle:[NSBundle mainBundle]];
NewNovelViewController *novelVC = [novelSB instantiateViewControllerWithIdentifier:@"NewNovelViewController"];
[self.navigationController pushViewController:novelVC animated:YES];
storyboard上创建一个scrollView(Xcode8)
1.点击VC的show the attributes inspector,将size设置成Freeform;
2.点击VC的show the size inspector,将高度设置成大约想滚动的高度,比如999;
3.在VC的view上添加scrollView,设置约束,比如scrollView[Top, Bottom, Leading, Trailing] = view[Top, Bottom, Leading, Trailing];
4.往scrollView上添加一个view作为contentView,设置view的约束(需要设置Top, Bottom, Leading, Trailing,Width,Height),Top, Bottom, Leading, Trailing,Width与scrollView相同即可,height设置成想要的,比如999;
5.往contentView上添加UI即可。
scrollView的导航偏移问题
遇到含导航栏的ViewController,其第一个子试图是UIScrollView会自动产生64像素偏移。 找了哈资料发现可以通过设置viewcontroller的self.automaticallyAdjustsScrollViewInsets = false解决了。
另外一个办法就去Storyboard上将ViewController 的Under Top Bar勾去掉也可以解决
参考https://www.swiftmi.com/topic/329.html
啊