0

I have created a "HorizontalSplit"-UIViewController. In that I created two UIViews as containers for other UIViewController. The height of the Containers is the half of the Screen.

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)
        ...
}

After that I put a new Controller in that View an used these lines of code:

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)
    }

I want that the SubViewController-Frame-Size (here called simple viewController) have the same size like the UIView-container that I added before. It works here because l and o (the variables) says the right height. But when my ViewController that I setup via the setTopViewController method on the HorizontalViewContrller the size is'n correct anymore. When I call on viewDidLoad 'self.view.bounds.height' on the subViewController it called the full size! And not the size I have set before... Why?

StefMa
  • 3,344
  • 4
  • 27
  • 48

1 Answers1

1

Ok, I found the solution. Thanks to these post of UIViewControllers lifecycle:

In the Sub-ViewController I've get the height in viewDidLoad but in there it haven't actually the settet frame size. Also with the help of these I found that the viewWillAppear have the settet height of the frame.

Hope that helps anyone too :)

Community
  • 1
  • 1
StefMa
  • 3,344
  • 4
  • 27
  • 48