I have a main view where there are buttons and google map.

let maps = MapView(frame: view.bounds) mapview = maps view.addSubview(mapview!) 

And by changing the user's state, details are added to the main view in the same way.

 let new = ButtonView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)) ButView = new view.addSubview(ButView!) 

When adding these views, my map is overlapped by layers of additional views and I cannot do any actions.

  • Create a custom view that will be added to your main view and this view should be under your map. And when creating new elements, add them not to the main view, but to the one you created. - Victor Mishustin
  • and if I add a view to the view which is under the map, if the added elements are not under the map - Chingiz Kuandyk

1 answer 1

You can make a specific View higher than others using:

 parentView.bringSubviewToFront(childView) 

Or you can set the setting for a specific View so that it does not respond to the touch.

 someView.isUserInteractionEnabled = false 

UPD: Try setting dimensions (or adjusting layouts) for the required view so that they do not overlap each other.

  • I have all views to respond to touch, I think when I specify the frame for the childview, it takes the bounds of the ViewController and overrides the main view - Chingiz Kuandyk
  • @ Chingiz Quandyk yes, this is possible. Better in this case to set the size for the desired view. - Vitaly