简体   繁体   English

隐藏超级视图而不隐藏其子视图

[英]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? 通常,我知道有解决方法,但是iOS SDK中有什么简单的方法可以隐藏超级视图而不隐藏其子视图?

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. 我想通过将其透明度设置为0或设置“隐藏”或某种方式来隐藏父级,问题是这些更改会影响父级的所有子视图。

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. 再一次,我意识到通常可以解决此问题,但是在这种情况下,我要处理mapView,并且子视图是注释和叠加层。

Thanks, -Matt 谢谢-马特

Update 更新

Yes, a MKMapView will have several layers in it with rendering, so setting backgroundColor wont work. 是的,MKMapView的渲染中将包含多个图层,因此设置backgroundColor无效。 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. 您可以尝试对MKMapView进行子类化,以添加一个属性来切换这些图层的开/关(通过将其删除/重新添加到视图中。)但是,这似乎很危险。

You could try setting the MKMApView's "clipsSubviews" to NO/FALSE, and reset the frame to 0,0,0,0. 您可以尝试将MKMApView的“ clipsSubviews”设置为NO / FALSE,然后将帧重置为0,0,0,0。 But this will impact your ability to get Touch events to your subviews. 但这将影响您将Touch事件获取到子视图的能力。

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设置为[UIColor clearColor]

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

superView.backgroundColor = .clear

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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