Iphone App in Landscape Mode, 2008 Systems

iPhone app in landscape mode, 2008 systems

Historic answer only. Spectacularly out of date.

Please note that this answer is now hugely out of date/

This answer is only a historical curiosity.


Exciting news! As discovered by Andrew below, this problem has been fixed by Apple in 4.0+.

It would appear it is NO longer necessary to force the size of the view on every view, and the specific serious problem of landscape "only working the first time" has been resolved.

As of April 2011, it is not possible to test or even build anything below 4.0, so the question is purely a historic curiosity. It's incredible how much trouble it caused developers for so long!


Here is the original discussion and solution. This is utterly irrelevant now, as these systems are not even operable.


It is EXTREMELY DIFFICULT to make this work fully -- there are at least three problems/bugs at play.

try this .. interface builder landscape design

Note in particular that where it says "and you need to use shouldAutorotateToInterfaceOrientation properly everywhere" it means everywhere, all your fullscreen views.

Hope it helps in this nightmare!

An important reminder of the ADDITIONAL well-known problem at hand here: if you are trying to swap between MORE THAN ONE view (all landscape), IT SIMPLY DOES NOT WORK. It is essential to remember this or you will waste days on the problem. It is literally NOT POSSIBLE. It is the biggest open, known, bug on the iOS platform. There is literally no way to make the hardware make the second view you load, be landscape. The annoying but simple workaround, and what you must do, is have a trivial master UIViewController that does nothing but sit there and let you swap between your views.

In other words, in iOS because of a major know bug:

[window addSubview:happyThing.view];
[window makeKeyAndVisible];

You can do that only once. Later, if you try to remove happyThing.view, and instead put in there newThing.view, IT DOES NOT WORK - AND THAT'S THAT. The machine will never rotate the view to landscape. There is no trick fix, even Apple cannot make it work. The workaround you must adopt is having an overall UIViewController that simply sits there and just holds your various views (happyThing, newThing, etc). Hope it helps!

Landscape Mode ONLY for iPhone or iPad

Code found here

Launching in Landscape Mode

Applications in iPhone OS normally
launch in portrait mode to match the
orientation of the Home screen. If you
have an application that runs in both
portrait and landscape modes, your
application should always launch in
portrait mode initially and then let
its view controllers rotate the
interface as needed based on the
device’s orientation. If your
application runs in landscape mode
only, however, you must perform the
following steps to make it launch in a
landscape orientation initially.

  • In your application’s Info.plist file, add the UIInterfaceOrientation

    key and set its value to the

    landscape mode. For landscape

    orientations, you can set the value

    of this key to

    UIInterfaceOrientationLandscapeLeft

    or

    UIInterfaceOrientationLandscapeRight.

  • Lay out your views in landscape mode and make sure that their
    autoresizing options are set
    correctly.

  • Override your view controller’s shouldAutorotateToInterfaceOrientation:
    method and return YES only for the

    desired landscape orientation and NO

    for portrait orientations.

Launching app in Landscape Mode

Instead of using [[UIScreen mainScreen] applicationFrame]

try using [[[[[self view] window] rootViewController] view] bounds]

The bounds will represent the width and height correctly in Landscape orientation, because the bounds will take into account the transform (rotation) that has been applied, while the frame will not.

To see what I mean, set a breakpoint, and in the debugger print out the description of the top level view lldb> po [[[[self view] window] rootViewController] view]

You'll see that the view has a rotation transform and that its frame does not represent the dimensions of the screen in landscape, but represents the dimensions in portrait!


The long way to calculate the correct applicationFrame would be

BOOL iOS7 = NO;
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending)
iOS7 = YES;

CGRect theFrame;
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
CGRect screenBounds = [[UIScreen mainScreen] bounds];

if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {

theFrame.origin = CGPointZero;
theFrame.size.width = screenBounds.size.height;
theFrame.size.height = screenBounds.size.width;

if (iOS7 == NO) {
// statusBarFrame will be CGRectZero if not visible, so this is safe
theFrame.size.height -= statusBarFrame.size.width; // because we're in landscape orientation
}
}
else {

theFrame = screenBounds;

if (iOS7 == NO) {
// statusBarFrame will be CGRectZero if not visible, so this is safe
theFrame.size.height -= statusBarFrame.size.height; // because we're in portrait orientation
}
}

Start app in landscape mode only and lock the application in landscape mode

You need to do this


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations;

return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight);

}

How to change the orientation to landscape right if the device is iPad

See my previous post:

Always open a view in potrait mode in view in ipad?

Make app start and remain in landscape mode

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


Related Topics



Leave a reply



Submit