Thanks to people on this board I am able to successfully calla up a child UIViewConroller via animation with:
This is the buttonAction from the Main UIViewController, which calls up setController
@objc func buttonAction(sender: UIButton!) {
guard let theButton = sender as? MyButton else { return}
UIView.transition(with: self.view, duration: 0.5, options: .transitionCurlDown, animations: { [self] in
self.addChild(setController);
self.view.addSubview(setController.view);
}, completion: { [self]_ in setController.didMove(toParent: self);
setController.doLayout();})
}
the doLayout method lies within the child:
func doLayout (){
guard let parent = cView!.view.superview else {return}
//make sure UIV honors safeAreaLayouts
setConstraints(vc: self, pc: parent)
}
A button within the child, setController, dismisses itself:
@objc func buttonAction(sender: UIButton!) {
self.willMove(toParent: nil)
self.removeFromParent()
self.view.removeFromSuperview()
self.dismiss(animated: false, completion: nil)
}
Everything works great the first time I call up the child UIView. It curls down while covering the first/parent UIVIEW, etc. etc. Figure 1 But after I dismiss the child view and call it again, the child view scrolls down without really covering the main view, it's like a mishmash. Figure 2 Only after all is said and done, then the child view covers everything.
So am curious if I am dismissing something incorrectly.