IPad app landscape launches portrait-sized root view controller

I have a new iPad project that only supports UIInterfaceOrientationLandscapeRight.

In my app div, I add RootViewController to the rootViewController window.

In this UIViewController (RootViewController) I have the following:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

      

I've also tried:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

      

However, I cannot get the correct dimensions for my application when I create and add subviews based on the dimensions of my view controller's view.

If I output self.view.frame for my view controller, I get {{0, 0}, {768, 1024}}

, but I would like {1024, 768} instead. If I can't when the dimensions are correct, so can I design my views with them in mind?

Sorry if this has been asked a billion times, I have looked through a lot of SO questions but nothing solved my problem.

+3


source to share


3 answers


I ran into the same question and what Ash Farrow said seems to be correct; the orientation is set after the call viewDidLoad

.

I was building an iPad app that works in all directions, but only the portrait orientation was setting correctly in my root UIViewController. In order to display vertices correctly in the terrain, I had to make sure the autoresist masks in all of my views were set up so that the view could tune to the landscape behind the scenes before being displayed to the user.

For example, I had a UIImageView that was the same size as the UIViewController UIView. To get it to adjust correctly when turning into terrain:



UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];    
backgroundImageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
[self.view addSubview:backgroundImageView];

      

The UIViewController can now be configured in portrait orientation in a method viewDidLoad

and nicely navigated to portrait orientation before being displayed to the user.

+5


source


EDIT:

It looks like the orientation of the interface is already set to viewDidLoad

p (UIInterfaceOrientation)[self interfaceOrientation]
(UIInterfaceOrientation) $1 = UIInterfaceOrientationLandscapeRight

      

Here's my theory: interfaces on iPad are, by default, 1024x768 if they have a status bar, which you do. I believe that while the orientation of the interface is correct, it doesn't update the view geometry until it does viewDidLoad

. I believe there is a good reason for this.

If you look at the UIViewController

lifecycle
, it viewDidLoad

is called as part of the view controller setting.After the view is loaded, it is called willAnimateRotationToInterfaceOrientation: duration:

to let your view controller know that its geometry is changing.



This is not so much an answer as an explanation. Hope this helps you create a solution for this problem.

Start an answer that doesn't actually work:

In info.plist

your project, open the option "Supported interfaces" and remove the screen orientation, you do not want to support. All are supported by default:

Supported Interface Orientations

This should clear it up.

+1


source


I have a simple solution, Apple's default app templates work with the XIB for the main view controller. To solve your problem, simply open the main XIB controller and set the orientation to "landscape".

As I usually do not use XIB and do not create all UI elements. This is why I had the same problem in previous projects that were really driving me crazy. I then solved it by hard-coding the frame width and height, not in a pretty way.

0


source







All Articles