我在主scrollView
中有一个storyboard
连接到三个不同的ViewControllers
,它们是启用了页面垂直滚动的xib文件。
一切正常,但我想知道是否有办法首先加载特定的viewController
。
viewControllers
名称为:
viewController1(notifications.xib)
viewController2(newViewController.xib)
viewController3(settings.xib)
ViewControllers
按顺序1,2,3加载,因此滚动只能从初始加载开始。
viewController1< - 这是构建应用时的初始加载
viewController2
viewController3
我希望初始加载位于viewController
2的中间位置,因此滚动可以从初始加载开始上下移动。
viewController1
viewController2< - 应用程序构建时,初始加载应为此
viewController3
来自主viewController.swift
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let notifications : notificationsView = notificationsView(nibName: "notificationsView", bundle: nil)
let newController : newViewController = newViewController(nibName: "newViewController", bundle: nil)
let settings : settingsView = settingsView(nibName: "settingsView", bundle: nil)
self.addChildViewController(newController)
self.scrollView.addSubview(newController.view)
newController.didMoveToParentViewController(self)
self.addChildViewController(notifications)
self.scrollView.addSubview(notifications.view)
notifications.didMoveToParentViewController(self)
self.addChildViewController(settings)
self.scrollView.addSubview(settings.view)
settings.didMoveToParentViewController(self)
//size of frames
var newControllerFrame : CGRect = newController.view.frame
newControllerFrame.origin.y = self.view.frame.height
newController.view.frame = newControllerFrame
var settingsFrame : CGRect = settings.view.frame
settingsFrame.origin.y = self.view.frame.height * 2
settings.view.frame = settingsFrame
self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height * 3)
我希望这会有所帮助,我们将非常感谢任何帮助或建议。
答案 0 :(得分:0)
所以基本上你想从中间而不是第一个开始?
如果是这样,你会做这样的事情。
CGPoint point = secondVC.frame.origin;
[scrollView setContentOffset:point animated: YES];