Not to update the subview with superview alpha val

2020-06-01 01:19发布

问题:

My question is when i added a view as subview to Root view.When i changed the alpha value of root view same is occurring in subview also.Actually i don't need the updating in subview.Is there any solution to do like that.

回答1:

This will change only the alpha of the root view, not the others

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


回答2:

Building on the answer by @shabbirv, one can also use IB's color picker



回答3:

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. When changing the layer's alpha it won't effect the subviews. 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.



回答4:

This will also solve this by changing root view color by below way, this will not affect the subview.

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


标签: iphone ios ios4