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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:22:17+00:00 2026-05-22T01:22:17+00:00

I have a UIView as a XIB in Portrait mode. This view is added

  • 0

I have a UIView as a XIB in Portrait mode.

This view is added programmatically to the viewcontroller like this:

NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"InputView" owner:self options:nil];
    InputView *inputView = (InputView*)[nibObjects objectAtIndex:0];
    [self.view addSubview:inputView];

This view has autoresizing masks set up properly and rotates fine when the orientation changes from Portrait to landscape.

However, if the orientation is already landscape and I create the view after the orientation change, it has its initial portrait orientation.

Is there a way to tell the view to initialize or resize itself to portrait by using its masks?

Thanks in advance for any reply!

EDIT:
Using the suggestions of occulus and Inder Kumar Rathore (thanks guys!), I altered the code to this:

InputView *inputView = (InputView*)[nibObjects objectAtIndex:0];
[self.view addSubview:inputView];
[self.view setNeedsLayout];
[self.view layoutSubviews];
[self.view layoutIfNeeded];
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
[self shouldAutorotateToInterfaceOrientation:orientation];

Unfortunately, there is no change at all.
I think I found someone asking the same question:

When adding a sub view the view does not resize if the app is in landscape mode

The answer identifies the problem correctly, but is not very encouraging…
Sure, I could create two nibs or resize the frame, but this seems so contrary to the idea of auto-resizing.
I find it hard to believe that there is no way to tell a nib after awakening and adding it to a view to use its autoresize features…something that works flawless when the device rotates.

EDIT 2:

The solution of idz works:

InputView *inputView = (InputView*)[nibObjects objectAtIndex:0];
[self.view addSubview:inputView];
inputView.frame = self.view.bounds;
[inputView show];

Thanks!

  • 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-22T01:22:17+00:00Added an answer on May 22, 2026 at 1:22 am

    Often a NIB/XIB file contains a UIViewController that takes care of all of this. In this case, since their is no view controller (in the NIB/XIB) you need to take over its post-load duties.

    Calling layoutSubviews directly, or indirectly via setNeedsLayout or layoutIfNeeded won’t do you much good because the default implementation does nothing.

    Assuming you want input view to fill the bounds of self.view you do the following:

    InputView *inputView = (InputView*)[nibObjects objectAtIndex:0];
    [self.view addSubview:inputView];
    inputView.frame = self.view.bounds;
    [inputView show];
    

    All the resize masks of the sub-views must be correctly set for this to work and, obviously, if you don’t want to fill the full bounds you may want to adjust the frame.

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

Sidebar

Related Questions

I have a xib with a root view that is a UIView subclass. How
I have a .xib file for my viewController. It contains a TableView and a
I am working on an iPhone application that runs in portrait mode only. This
I have an xib with a single UIView containing a bunch of images and
I have added a XIB based UIViewController to my solution and dragged some UIViews
I have a RootViewController & it's associated nib or xib file. This nib is
Say that I have a UIView which I would like to re-use in multiple
I have a xib-file with a small UIView on it, which in turn contains
I have a subclass of UIView that's instantiated in a XIB file. I need
I'm drawing a custom UIView that is sitting inside a xib whose ViewController is

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.