I am using parent view controller and child view controller in my app. In which parent view controller contains subview as button with zPosition value of 2.
Now, i am adding child view controller to parent as below,
func addChildViewController(){
let storyboard = UIStoryboard(name: "myStoryBoard", bundle: nil)
let childVC = storyboard.instantiateViewController(withIdentifier: "childVC") as! ChildViewController
addChildViewController(childVC)
self.view.addSubview(childVC.view)
childVC.didMove(toParentViewController: self)
}
Button subview is visible at top of child view controller, but click event is not firing.
Note : I am not adding button as subview on child view controller, only at parent view controller.
Is the childVC covering the button? - You need to make sure that the subview with the button in it is moved to the front after you add the childVC.
func addChildViewController(){
let storyboard = UIStoryboard(name: "myStoryBoard", bundle: nil)
let childVC = storyboard.instantiateViewController(withIdentifier: "childVC") as! ChildViewController
addChildViewController(childVC)
self.view.addSubview(childVC.view)
childVC.didMove(toParentViewController: self)
// Bring button subview to front
self.view.bringSubviewToFront(SubViewWithButtonIn)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With