Need Help Checking What Orientation iPad is in [duplicate]
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 b开发者_Python百科ut 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?
There are several ways to achieve what you want, more or less:
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
- 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;
}
UIInterfaceOrientation orientation = [UIDevice currentDevice].orientation;
精彩评论