简体   繁体   中英

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

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]

您可以将超级视图的backgroundColor属性设置为.clear ,这.clear视图的外观没有影响。

superView.backgroundColor = .clear

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM