1

我有一个 rootview 控制器,其中我从情节提要添加了一个 splitview 控制器,并动态地将另一个 SecondView 控制器作为子级添加到 rootview 控制器。我面临的问题是方向上从 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)
4

0 回答 0