views:

374

answers:

2

I have a question similar to the http://stackoverflow.com/questions/1269637/can-you-override-a-parent-uiviews-alpha-value-on-one-of-its-subviews

In some cases I want to show custom semi-transparent full-screen overlay view over current view. The trick is that I want it to have custom navigation bar at the top and some other contents (let it be label) and I'd like the navigation bar to be opaque i.e. paint over everything on the original view. At the same time I'd like all other contents to be semi-transparent. I don't want to interfere with main view's navigation bar because there might be no navigation bar at all. I'd like to create a single container view with navigation bar and all other contents on it and add it to the window. But none of combinations of background color and alpha for container, navigation bar and contents I can come up with seems to work.

The question I found suggests that it is impossible if container view is not opaque. My case might be slightly different because there is a simple border-line between transparent and opaque parts. So I still hope that there is some easy way. Or do I have to manage opaque navigation bar and transparent contents views separately anyway?

+1  A: 

If I understand your question correctly, you should make your container view completely transparent (backgroundColor = [UIColor clearColor]) and add the opaque navigation bar and a semi-opaque content view to the container view.

Ole Begemann
Thank you, that seems to be exactly what I need. I tried to set colors and alpha in Interface Builder and I still can't see clearColor. If I set it programmatically in viewDidLoad, it works perfectly. Thank you again.
iPhone beginner
A: 

Edit: Disregard this answer. I misunderstood the question.

The previous post's answer is incorrect (as I understood the question.) The alpha for each individual view is set independently. You need to adjust the alpha to the level you want as you add each view, in Interface Builder or after you load from nib.

If you don't want to cover the navigation bar, you can (1) make position the overlay view's frame below the navigation bar or (2) create two sibling views in the overlay view, one view is transparent over the navigation bar and the other has your translucent elements.

TechZen
As I commented on your other answer, the previous post's answer is correct. Even though each subview's alpha can be set independently of the main view's, they are composited in the order of their place in the view hierarchy. The subview's alpha is effectively multiplied by the main view's.
Brad Larson
I see, I did misunderstand.
TechZen