Chilld视图控制器在以编程方式添加时不会在旋转时调整大小

时间:2017-06-12 12:08:31

标签: ios swift autoresizingmask childviewcontroller splitview

我是一个rootview控制器,我从故事板中添加了一个splitview控制器,并动态地将另一个SecondView控制器作为子节点添加到rootview控制器中。问题我面临的是on orientation第二视图控制器从Rootview控制器中删除,splitview占用整个视图框架。 以下是我添加子视图的代码

let menuVC   =  self.storyboard?.instantiateViewController(withIdentifier: "INSPSortFilterViewController") as! INSPSortFilterViewController
    menuVC.filterClose = self
    var sortingViewWidth:CGFloat? = 0.0

    if  islandscape
    {
        sortingViewWidth = UIScreen.main.bounds.size.width/3
        menuVC.viewWidth = sortingViewWidth! - 20

    }
    else
    {
        sortingViewWidth = UIScreen.main.bounds.size.width/2
        menuVC.viewWidth = sortingViewWidth! - 20

    }
    self.splitViewController?.parent?.view.addSubview(menuVC.view)
    self.splitViewController?.parent?.addChildViewController(menuVC)
    menuVC.didMove(toParentViewController: self.splitViewController?.parent)
    menuVC.view.layoutIfNeeded()
    menuVC.sortingAndFilterProtocol = viewModel
    menuVC.filterClose = self
    menuVC.jobList = viewModel?.actualJobList
    menuVC.filteredJobList = self.jobList

    let navigationBarHeight = ((self.navigationController?.navigationBar.frame.size.height)! + UIApplication.shared.statusBarFrame.size.height)
    menuVC.view.frame=CGRect(x: 0, y: 0+navigationBarHeight, width: sortingViewWidth!, height: UIScreen.main.bounds.size.height)

    let slideInFromLeftTransition = Utility.sharedInstance.getTransition(type: Transition.Left)

    // Add the animation to the View's layer
    menuVC.view.layer.add(slideInFromLeftTransition, forKey: "slideInFromLeftTransition")


    UIView.animate(withDuration: 0.3, delay: 0.0, options: .curveEaseInOut, animations: { () -> Void in
        self.splitViewController?.view.frame=CGRect(x: sortingViewWidth!, y: 0, width: (UIScreen.main.bounds.size.width), height: UIScreen.main.bounds.size.height)
    }, completion:nil)

0 个答案:

没有答案