我創建了一個「HorizontalSplit」 - UIViewController
。在此我創建了兩個UIView
作爲其他UIViewController的容器。容器的高度是屏幕的一半。設置Sub-UIViewController框架高度
override func viewDidLoad() {
super.viewDidLoad()
...
self.topViewContainer = UIView(frame: CGRectMake(0, 0, self.view.bounds.width, completeHeight/2))
self.topViewContainer.backgroundColor = UIColor.orangeColor()
self.view.addSubview(topViewContainer)
self.bottomViewContainer = UIView(frame: CGRectMake(0, completeHeight/2, self.view.bounds.width, completeHeight/2))
self.bottomViewContainer.backgroundColor = UIColor.blueColor()
self.view.addSubview(bottomViewContainer)
...
}
之後,我把一個新的控制器在該視圖的代碼中使用這些行:
func setTopViewController(viewController: UIViewController) {
if self.topViewController != nil {
self.topViewController.removeFromParentViewController()
self.topViewController.view.removeFromSuperview()
}
var l = topViewContainer.frame.height
self.topViewController = viewController
self.topViewController.view.frame = CGRect(x: 0, y: 0, width: topViewContainer.bounds.width, height: topViewContainer.bounds.height)
var o = topViewController.view.frame.height
self.addChildViewController(self.topViewController)
self.topViewContainer.addSubview(self.topViewController.view)
self.topViewController.didMoveToParentViewController(self)
}
我想的是,SubViewController幀尺寸(這裏稱爲簡單的viewController)具有相同的大小就像我之前添加的UIView容器一樣。 它在這裏工作,因爲l和o(變量)表示正確的高度。但是當我通過HorizontalViewContrller上的setTopViewController方法設置的ViewController的大小不再正確時。 當我調用subViewController上的viewDidLoad'self.view.bounds.height'時,它調用了全尺寸!而不是我之前設定的尺寸...爲什麼?