0

Possible Duplicate:
iPhone orientation

Depending on what orientation the iPad is in, I need to either set the table view's background or remove it because it doesn't work with the popover.

I tried this but no luck:

if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft ){
    self.navigationController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]; 
    self.tableView.backgroundColor = [UIColor clearColor];
    NSLog(@"test");

Maybe there is a better way? To see if table is master or popover, then set background?

Community
  • 1
  • 1

2 Answers2

4

There are several ways to achieve what you want, more or less:

  1. UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
  2. A more hack-ish method would be to check the width of the status bar.

If you go with option 1, then you can check the orientation like so:

switch (orientation) {
    case UIInterfaceOrientationPortrait:
        // Do something.
        break;
    case UIInterfaceOrientationPortraitUpsideDown:
        // Do something.
        break;
    case UIInterfaceOrientationLandscapeLeft:
        // Do something.
        break;
    case UIInterfaceOrientationLandscapeRight:
        // Do something.
        break;
}

EDIT: To get your application to automatically rotate, you can do this:

- (BOOL)willAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if ((interfaceOrientation == UIDeviceOrientationLandscapeRight)) NSLog(@"Right");
    if ((interfaceOrientation == UIDeviceOrientationLandscapeLeft)) NSLog(@"Left");
    if ((interfaceOrientation == UIDeviceOrientationPortrait)) NSLog(@"Up");
    if ((interfaceOrientation == UIDeviceOrientationPortraitUpsideDown)) NSLog(@"Down");
    return YES;
}
FreeAsInBeer
  • 12,937
  • 5
  • 50
  • 82
  • Ok if I go with option one. How do I retrieve the orientation from that code and use an if/else statement depending on orientation? –  Aug 19 '11 at 03:24
2
UIInterfaceOrientation orientation = [UIDevice currentDevice].orientation;
Peter DeWeese
  • 18,141
  • 8
  • 79
  • 101