views:

1329

answers:

2

Hi Stackoverflow,

what is the appropriate way to overlay two layers of an UIView for the iPhone? The underlaying view should be active until a button is pressed, then another UIView should cover everything in a transparent way. I found the Modal View Controllers, but they simply exchange UI-Views but don't overlay.

Thanks in advance.

Chris

+1  A: 

You should use [existingView addSubView:newView]; to add a view to an existing view. the newView will appear on top of the existingView. So conceptually, you would create a button on existingView, connect it to an IBAction that calls a method like this:

CGRect newSize = CGRectMake(0.0f ,0.0f, 320.f, 400.0f);
UIView *newView = [[UIView alloc] initWithFrame:newSize];
[existingView addSubView:newView];
[newView release];

This will place a newView on top of the existingView.

Jordan
Small typo: [existingView addSubview:newView];
Chris
A: 

Hi, excellent response Jordan & Chris. Thanks! To get rid of the view, once a user has pressed the close button, would I pop the view controller? Or do I need to do

[existingView popViewControllerAnimated:YES]

or

[existingView removeFromSuperview:newView];

I think the ladder, but I'd like a confirmation.

Thanks!

Michael
Hi Michael, the removeFromSuperview is correct
Chris
@Chris, Thanks!
Michael