mag725
mag725

Reputation: 705

Hiding a superview without hiding its subviews

generally I know there are workarounds for this, but is there any simple way in the iOS SDK to hide a superview without hiding its subviews?

I have a parent view that is a background to a few other views. I would like to hide the parent, either through setting its transparency to 0, or setting "hidden" or something - the issue is that these changes affect all of the subviews of the parent.

Again, I realize that there is usually a way around this, but in this case I am dealing with a mapView, and my subviews are annotations and overlays.

Thanks, -Matt

Upvotes: 3

Views: 2379

Answers (2)

ScottyBlades
ScottyBlades

Reputation: 14073

You can set the backgroundColor property of the super view to .clear and this will have no effect on the appearance of the subview.

superView.backgroundColor = .clear

Upvotes: 0

TomSwift
TomSwift

Reputation: 39502

Update

Yes, a MKMapView will have several layers in it with rendering, so setting backgroundColor wont work. You could try subclassing MKMapView to add a property to toggle these layers on/off (by removing/re-adding them to the view.) But this seems pretty dangerous.

You could try setting the MKMApView's "clipsSubviews" to NO/FALSE, and reset the frame to 0,0,0,0. But this will impact your ability to get Touch events to your subviews.

It's likely a better solution to re-evaluate your view hierarchy. Make it something like:

main-view
  map-view
  transparent-view
    control-1
    control-2
    etc.

Original

Set the backgroundColor to [UIColor clearColor]

Upvotes: 1

Related Questions