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 7879557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:55:20+00:00 2026-06-03T03:55:20+00:00

I’ve got a massive problem and I really hope you can help me here…

  • 0

I’ve got a massive problem and I really hope you can help me here… I’m very lost at the moment 🙁

I’ve got a project that runs with a MainWindow.xib. In my app delegate file I check the orientation of the device and load an appropriate NIB file that have different layouts (subviews) based on orientation. Here is the code to check the orientation:

-(void)checkTheOrientation
{
    if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) 
    {
        viewController = [[[MyViewController alloc] initWithNibName:@"MyWideViewController" bundle:nil] autorelease];
        NSLog(@"Landscape = MyWideViewController");
    } 
    else if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown)
    {   
        viewController = [[[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil] autorelease];
        NSLog(@"Portrait = MyViewController"); 
    }
}

This works as expected and in Landscape or Portrait I am loading the correct views. The portrait view loads perfectly but the Landscape view loads with a thick black edge to the left as if it’s x & y positions are not set to 0 & 0 respectively.

Here is the portrait view: http://uploads.socialcode.biz/2f25352B0e3x3z2t2z21
Here is the landscape view with the bug: http://uploads.socialcode.biz/1G2k3T012d1z0Y1U2q1k

In the MyViewController.m file I have a rough fix to get the sizing done correctly to avoid this big black strip on the left. Here’s the code for this:

- (void) performLayout {
    // Ensure the main view is properly placed
    NSInteger MaxSizeHeight, MaxSizeWidth;

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    {
        MaxSizeHeight = 1024;
        MaxSizeWidth  = 768;
    }
    if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
        CGRect mainViewFrame = [[self view] frame];
        float width = mainViewFrame.size.width;
        mainViewFrame.size.width = mainViewFrame.size.height;
        mainViewFrame.size.height = width;
        mainViewFrame.origin.x = 0;
        mainViewFrame.origin.y = 0;
        [[self view] setFrame:mainViewFrame];
    } else {
        CGRect mainViewFrame = [[self view] frame];
        mainViewFrame.origin.x = MaxSizeWidth - mainViewFrame.size.width;
        mainViewFrame.origin.y = MaxSizeHeight - mainViewFrame.size.height;
        [[self view] setFrame:mainViewFrame];
    }

    // Ensure the content view is properly placed
    CGRect contentFrame = [mainContentView frame];
    if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) 
    {
        contentFrame.size.width = MaxSizeHeight;
        contentFrame.size.height = MaxSizeWidth;
    }
    contentFrame.origin.x = 0;
    contentFrame.origin.y = 44;
    [mainContentView setFrame:contentFrame];

    // Ensure the content subviews are properly placed
    contentFrame.origin.y = 0;
    for (UIView *contentView in [mainContentView subviews]) {
        [contentView setFrame:contentFrame];
    }
}

The problem with this method is that this is just a very bad hack and it’s not actually solving my problem. When it loads up in Landscape it now resizes and positions the subview to 1024×768,0,0 but any additional subviews that I load via other NIBs have the same problem.

What I would really like to know is how on earth can I set the landscape main superview to be 1024×768 position 0 & 0 without having to try and hack this together and keep performing the performLayout selector? At the moment there is a lot of inconsistence with this as the hack doesn’t actually set the superview sizing correctly but rather just the subviews I load on top of the superview.

I thought that maybe a simple fix like this might solve the superview issue but alas it doesn’t:
window.frame = CGRectMake(0, 0, 1024, 768);

I just want my main superview to be the placed and sized correctly at load and then the superviews just load in the right place. Please can you help me here???

  • 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-06-03T03:55:21+00:00Added an answer on June 3, 2026 at 3:55 am

    First, UIView has a method named -layoutSubviews that you can override to position the subviews however you like. It’ll be called when the view is first loaded, and again before drawing if you ever send it a -setNeedsLayout message.

    Second, you should be able to properly set these positions in your .xib or storyboard file. Select your main view in its .xib file and check its position in the Size inspector. Also, ensure that the view is set to Landscape orientation in the Attributes inspector. If it’s all correct, then there’s something else going on. To simplify the problem, make a new project in Xcode with nothing but an empty view in landscape orientation. I just did one, and there’s no position problem. That’s what you want in your real app, so figure out what’s happening in your real app to affect the view’s position that’s not happening in your new sample app.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
i got an object with contents of html markup in it, for example: string
Does anyone know how can I replace this 2 symbol below from the string

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.