views:

86

answers:

3

Hello All,

Im writing an app that I would like to display different views based on orientation. For example, if the device is portrait load pView, if landscape load lView. Below is the code ive currently tried.

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)
interfaceOrientation duration:(NSTimeInterval)duration {
 if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
      self.view = portrait;
}
 else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
      self.view = portrait;
 }
 else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){
      self.view = portrait;
 }
 else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
      self.view = landscape;
 }

}

With this I have created 2 views in IB and connected the outlets to the right view. Ive also tried this:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)
interfaceOrientation duration:(NSTimeInterval)duration {
 if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
      self.view = portrait;
}
 else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
      self.view = portrait;
 }
 else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){
      lView *abo = [[lView alloc] initWithNibName:@"lView" bundle:nil];
      [self.navigationController pushViewController:abo animated:NO];
      [abo release];

 }
 else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
      lView *abo = [[lView alloc] initWithNibName:@"lView" bundle:nil];
      [self.navigationController pushViewController:abo animated:NO];
      [abo release];

 }

}

The code directly above worked for ipod but not ipad. Any ideas?

A: 

I have to ask the obvious question:

Do you have the screen orientation lock switch turned on for your iPad?

Chris
No, im trying to load a different view based on orientation.
Tanner
A: 

Depending on what you are trying to do, you can set up your interface in IB to handle rotations automatically. You can resize components, move pics and labels around, stuff like that. That may do what you want to do...

Geoff Baum
A: 

I found the following 2 (Apple) sample projects useful:

http://developer.apple.com/library/ios/#samplecode/AlternateViews/Introduction/Intro.html

http://developer.apple.com/library/ios/#samplecode/WhichWayIsUp/Introduction/Intro.html

Also, remember from a device perspective there is also face-up and face-down orientations; this caught me out.

petert