Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4271430
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:26:28+00:00 2026-05-21T07:26:28+00:00

The Problem: I have two View Controllers loaded into a root View Controller. Both

  • 0

The Problem:
I have two View Controllers loaded into a root View Controller. Both sub view layouts respond to orientation changes. I switch between the two views using [UIView transformationFromView:…]. Both sub views work fine on their own, but if…

  1. Views are swapped
  2. Orientation Changes
  3. Views are swapped again

the View that was previously hidden has serious layout problems. The more I repeat these steps the worse the problem gets.

Implementation Details

I have three viewsControllers.

  1. MyAppViewController
  2. A_ViewController
  3. B_ViewController

A & B ViewControllers have a background image each, and a UIWebView and an AQGridView respectively. To give you an example of how i’m setting it all up, here’s the loadView method for A_ViewController…

- (void)loadView {

    [super loadView];

    // background image
    // Should fill the screen and resize on orientation changes
    UIImageView *bg = [[UIImageView alloc] initWithFrame:self.view.bounds];
    bg.contentMode = UIViewContentModeCenter;
    bg.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    bg.image = [UIImage imageNamed:@"fuzzyhalo.png"];
    [self.view addSubview:bg];

    // frame for webView
    // Should have a margin of 34 on all sides and resize on orientation changes
    CGRect webFrame = self.view.bounds;
    webFrame.origin.x = 34;
    webFrame.origin.y = 34;
    webFrame.size.width = webFrame.size.width - 68;
    webFrame.size.height = webFrame.size.height - 68;

    projectView = [[UIWebView alloc] initWithFrame:webFrame];
    projectView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

    [self.view addSubview:projectView];

}

For the sake of brevity, the AQGridView in B_ViewController is set up pretty much the same way.

Now both these views work fine on their own. However, I use both of them in the AppViewController like this…

- (void)loadView {

        [super loadView];

        self.view.autoresizesSubviews = YES;
        [self setWantsFullScreenLayout:YES];

        webView = [[WebProjectViewController alloc] init];
        [self.view addSubview:webView.view];

        mainMenu = [[GridViewController alloc] init];
        [self.view addSubview:mainMenu.view];

        activeView = mainMenu;

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(switchViews:) name:SWAPVIEWS object:nil];


    }

and I switch betweem the two views using my own switchView method like this

- (void) switchViews:(NSNotification*)aNotification;
{
    NSString *type = [aNotification object];

    if ([type isEqualToString:MAINMENU]){
        [UIView transitionFromView:activeView.view toView:mainMenu.view duration:0.75 options:UIViewAnimationOptionTransitionFlipFromRight completion:nil];
        activeView = mainMenu;
    }

    if ([type isEqualToString:WEBVIEW]) {
        [UIView transitionFromView:activeView.view toView:webView.view duration:0.75 options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
        activeView = webView;
    }

    // These don't seem to do anything
    //[mainMenu.view setNeedsLayout];
    //[webView.view setNeedsLayout];

}

I’m fumbling my way through this, and I suspect a lot of what i’ve done is implemented incorrectly so please feel free to point out anything that should be done differently, I need the input.

But my primary concern is to understand what’s causing the layout problems. Here’s two images which illustrate the nature of the layout issues…

UPDATE:
I just noticed that when the orientation is landscape, the transition flips vertically, when I would expect it to be horizontal. I don’t know wether that’s a clue as to what might be going wrong.

Normal Layout

Switch to the other view… change orientation…. switch back….

Problem Layout

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:26:29+00:00Added an answer on May 21, 2026 at 7:26 am

    I just stumbled across this and have a feeling you have since figured this out. But just in case, or if someone else is searching for the same answer, this is the approach I have taken in the situation.

    In each view controller’s header files (the ones you switch between, not the root MyAppViewController), add a float:

    float boundWidth;
    

    In viewDidLoad, initialize it to 0

    boundWidth = 0;
    

    Then create a check such as the following:

    - (void)viewDidAppear:(BOOL)animated {
    // check to see what orientation the device is in;
       if ((boundWidth != 0) && (boundWidth != self.view.bounds.size.width)) {
          // the orientation has changed, so insert code to deal with this;
    }
    

    Keep track of the width by setting it when you leave the view:

    - (void)viewDidDisappear:(BOOL)animated {
       boundWidth = self.view.bounds.size.width;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two view controllers: LocationsViewController , and SettingsViewController . LocationsViewController conforms to the
I have a tab bar application and when I display a modal view controller,
I have a navigation controller app. I created a RootViewController class with Xib file.
My app has two distincts modes. There's a tab bar controller in the app
I have my main program with MainAppDelegate.h,MainAppDelegate.m . I have created two custom navigation
I have to upgrade one existing application and neeed to split its existing UI
I had one of my colleagues come to me today with a problem of
Update: Solved. See fix at bottom. In my iPad app which supports all orientations,
I am working on an app to try and learn a bit more about
My situation is as follows: My class SettingsViewController is a subclass of UINavigationController .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.