IOS: UIView with Preview. Button click event does not fire when zPosition of view changes

I am using the parent view controller and the child view controller in my application. In which the parent view controller contains a subview as a button with a value of zPosition 2.

Now I add the controller of the child view to the parent, as shown 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 mobility is visible at the top of the child view controller, but the click event does not fire.

Note . I do not add a button as a subview in the controller of the child view only in the parent view.

+4
source share
1 answer

childVC ? - , subview ​​ 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)

}
+1

Source: https://habr.com/ru/post/1671794/


All Articles