【发布时间】:2014-10-09 13:37:49
【问题描述】:
我创建了一个“HorizontalSplit”-UIViewController。我创建了两个UIViews 作为其他 UIViewController 的容器。 Containers 的高度是屏幕的一半。
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-Frame-Size(这里称为简单 viewController)具有与我之前添加的 UIView-container 相同的大小。 它在这里有效,因为 l 和 o (变量)表示正确的高度。但是,当我通过 HorizontalViewContrller 上的 setTopViewController 方法设置的 ViewController 时,尺寸不再正确。 当我在 subViewController 上调用 viewDidLoad 'self.view.bounds.height' 时,它调用了全尺寸!而不是我之前设置的尺寸......为什么?
【问题讨论】:
标签: ios uiviewcontroller swift