1
votes

What is the safest and most effective way place a new UIView within the bounds of the App's UIWindow on the top of the view stack when a screen rotation from Portrait to Landscape occurs? Also, when returning from Landscape to Portrait, to remove this subview.

Basically the App is created as most are:

-UIWindow:

--UIView

---All subviews (including a tabview controller)

I would like to create:

-UIWindow:

--UIView (new, to be placed on top)

--UIView

---All subviews (and triggered by a view controller in here)

Is this wrong? There is surprisingly little documentation to help do this.

3

3 Answers

1
votes

If you create a view controller to hold all of your subviews you can just use the rotation functions that will be called for you:

willRotateToInterfaceOrientation:duration: and didRotateFromInterfaceOrientation:

So lets say you use didRotateFromInterfaceOrientation you check

if(UIInterfaceOrientationIsLandscape(orientation))
{
    [yourView removeFromSuperView];
}
else
{
    [self.view addSubView: yourView];
}
1
votes

See my answer here: https://stackoverflow.com/a/4960988/202451

It should bring you closer to doing custom things like that

0
votes

I found the a working solution. Might you offer a better one?

    ArtsDayAppDelegate *appDelegate = (ArtsDayAppDelegate*)[[UIApplication sharedApplication] delegate];
    UIView *landscapeView;

    if (!landscapeView) {
        landscapeView = [[UIView alloc] initWithFrame: frame];
    }

    [landscapeView setBackgroundColor:[UIColor blackColor]];
    ..add various views..
    [appDelegate.window.rootViewController.view addSubview:landscapeView];