0

I have a MasterViewController and I am adding a ChildViewController inside a MasterViewController. Inside MasterViewController I have made top button bar , and took a view as a Container view. In this container view I want to move my ChildViewControllers. And This will happen on button click in MasterViewController

This is how I am adding the ChildViewController

func addViewControllerAsChildViewController(childVC : UIViewController) {
    oldVC = newVC
    childVC.view.frame  = viewContainer.bounds
    childVC.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    addChildViewController(childVC)
    childVC.didMove(toParentViewController: self)
    // Where ViewContainer is dedicated area inside the MasterViewController
    viewContainer.addSubview(childVC.view)
}

And these are my button clicks

 @IBAction func onClickBtnNewList(_ sender:  UIButton) {
    if !(newVC is NewListVC) {
        initNewListVC()
        addViewControllerAsChildViewController(childVC: targetViewController)
    }
    UIView.animate(withDuration: 4000, animations: {
        self.viewIndicators.frame = sender.frame.offsetBy(dx:0,dy:2)
    })
}

@IBAction func onClickBtnSavedList(_ sender: UIButton) {
    if !(newVC is SavedListVC) {
        initSavedListVC()
        addViewControllerAsChildViewController(childVC: targetViewController)
    }
    UIView.animate(withDuration:400, animations: {
        self.viewIndicators.frame = sender.frame.offsetBy(dx:0,dy:2)
    })
}

My ChildViewControllers gets inflated correctly. But Problem is on button Click there is a another view, which I am animating on click and moving it below the button. You can see I have used the following code in button click. The animation start and ended moving my related view to its starting position. and its not moving to my expected area see code below

UIView.animate(withDuration: 4000, animations: {
    self.viewIndicators.frame = sender.frame.offsetBy(dx:0,dy:2)
})

but this is not working. But If I comment out following lines that are attaching ChildViewController , The animation do move smoothly and View moves to the target area

/*
if !(newVC is NewListVC) {
    initNewListVC()
    hideOrShowViewController(targetViewController: newVC!)
}
*/

Now do you have any idea why it is happening ?? what could be problem? I am using Xcode 9 and swift 4 Please help

Anters Bear
  • 1,816
  • 1
  • 15
  • 41
Android teem
  • 780
  • 2
  • 13
  • 36
  • Are you sure your `ChildViewController` should be a `UIViewController` and not a `UIView`? – Anters Bear Aug 29 '18 at 11:03
  • Is that 4000 seconds? – Przemysław Wrzesiński Aug 29 '18 at 11:12
  • Also how can I tell you what is wrong with the code you are commenting out if the two methods `initNewListVC` and `hideOrShowViewController` it calls are left out of your questions description? One of these methods is obviously causing the problem? – Anters Bear Aug 29 '18 at 11:12
  • @AntersBear Yes I am sure – Android teem Aug 29 '18 at 11:52
  • @PrzemysławWrzesiński forget about timing , well I am using .400 delay – Android teem Aug 29 '18 at 11:52
  • @AntersBear listen , the commented out lines are the lines which inflate the ChildViewController in the containerUiView that I made inside the Parent/master viewController. I was just trying to clear that when I commnent out those lines, Animations works well, but When I un comment those lines, Animations does not even work – Android teem Aug 29 '18 at 11:55

0 Answers0