Question

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

Was it helpful?

Solution

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.

OTHER TIPS

following is a simple 3 line ARC-compatible with transparent overlay for UIView

_overlayView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
  _overlayView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
    [self.view addSubview:_overlayView];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top