1

i've a rootview contoller in which i've added a splitview controller from storyboard and dynamically i'm adding another SecondView controller as a child to rootview controller.Issue i'm facing is on orientation Second View controller removed from Rootview Controller and splitview occupies the complete view frame. Below is my code of adding child view

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)
Nitisha Sharma
  • 239
  • 4
  • 14

0 Answers0