0
votes

I just want to be sure :

I have main view controller(uiviewcontroller) then I had child view controller(uiviewcontroller) that cover it then I add subview (uiview) to the main view controller with the same size.

If I do it in that order, what the user will see on top ? the subview(uiview) or the child view controller (uiviewcontroller) ?

I test it, and the only way to make the subview on top is to add it to the child view controller( uiviewcontroller).

This is the way the view hierarchy should be ? or my test is wrong (can be)

EDIT: I want to use only addSubView, to understand what is the default behaviour.

EDIT 2 : on view debugger i can see the subview on top but not with the device.

3

3 Answers

0
votes

Try this

self.view.insertSubview(VC1.view, belowSubview: thatview)
0
votes

The top view will be the view added to the subview hierarchy at last.

if you want to bring the subview to top you can you the below code

mainViewController.view.bringSubview(toFront: subView)

you don't need to add it to the child view controller

0
votes

Found the bug.

Other views had bringSubViewToFront / layer.zPosition, some of them inside viewDidLayoutSubview, after I disable this code, everything works O.K

What confused me is the view debugger show the view on top, but on the device it was hidden.