tags:

views:

391

answers:

1

I am adding a modal view using the following code:

[self presentModalViewController:phrasesEditor animated:YES];

How can I make the modal view semi-transparent so that the superview "shines" through?

My complete method/function looks like this:

-(IBAction)showEditPhrases:(id)sender{
    PhrasesViewController *phrasesEditor = [[PhrasesViewController alloc] initWithNibName:@"PhrasesViewController" bundle:nil];
    phrasesEditor.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [phrasesEditor.view setAlpha: 0.5];
    [phrasesEditor.view setBackgroundColor: [UIColor clearColor]];
    [self presentModalViewController:phrasesEditor animated:YES];
    [phrasesEditor release];
}

EDIT:

The pragmatic approach of changing the alpha will not work, apparently. How can I load a NIB into a UIView and interact with it?

I have a UIViewController now. Do I convert/modify/change it into a UIVIew and then load it, or am I supposed to do something else?

EDIT 2:

I tried [self.view addSubview:phrasesEditor.view];, but that leaves me with no way to remove the subview. Each view seems to have its own View Controller.

EDIT 3:

I thought that I should mention that the superview is inside of a view controller called iDecideViewController and the phrasesEditor has a separate View Controller.

A: 

When you present a modal view it will actually unload the previous view so that is not what you want at all. UIView has a method called addSubview which will put the new view on top of its siblings.

Instead of:

[self presentModalViewController:phrasesEditor animated:YES];

do:

[self.view addSubview:phrasesEditor.view];

This is assuming you are already in a ViewController subclass.

willcodejavaforfood
I tried that, but then how do I unload it?
Moshe
removeFromSuperview on phrasesEditor.view
willcodejavaforfood
I'm not sure about that. It has a separate View Controller from phrases editor and causes EXC_BAD_ACCESS
Moshe
EDIT: I figured it out. I was `[phraseEditor release]` ing too early.
Moshe
So now I'm leaking memory, gotta take of that.
Moshe
Taken care of. I've decided to stick with `[self presentModalViewController:phrasesEditor animated:YES];` and apply a background image to that via UIImage. Problems solved.
Moshe
Glad you could resolve it :)
willcodejavaforfood