简体   繁体   English

不要使用superview alpha值更新子视图

[英]Not to update the subview with superview alpha value

我的问题是当我将视图作为子视图添加到根视图时。当我更改根视图的alpha值时,同样在子视图中也发生。实际上我不需要在子视图中进行更新。是否有任何解决方案可以做到这一点。

这将仅更改根视图的alpha,而不更改其他视图的alpha

    self.view.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5];

Building on the answer by @shabbirv, one can also use IB's color picker 在@shabbirv的答案基础上,人们也可以使用IB的颜色选择器

颜色选择器

You'd need to change the structure of your views. 您需要更改视图的结构。 Instead of laying your subviews out on the roots view, create a layer ontop of your root view, but still add the subviews to the root. 不要在子视图上放置子视图,而是在根视图的ontop上创建一个图层,但仍然将子视图添加到根。 When changing the layer's alpha it won't effect the subviews. 更改图层的alpha时,它不会影响子视图。 Example structure below. 下面的示例结构。

Your current structure: 你目前的结构:

RootView->Subviews //Changing RootView alpha effects Subviews.

Needed Structure: 需要的结构:

RootView->View->Subviews(Still Added to RootView) //Changing alpha of Layer doesn't effect subviews.

Hope this helps. 希望这可以帮助。

这也将通过以下方式改变根视图颜色来解决这个问题,这不会影响子视图。

[rootView setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.7]];

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

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