可能重复:
iPhone orientation
根据iPad的方向,我需要设置表格视图的背景或删除它,因为它不适用于弹出窗口。
我试过这个但没有运气:
if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft ){
self.navigationController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
self.tableView.backgroundColor = [UIColor clearColor];
NSLog(@"test");
也许有更好的方法?要查看表是主表还是弹出表,请设置背景?
答案 0 :(得分:4)
有多种方法可以实现您想要的,或多或少:
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
如果你选择选项1,那么你可以像这样检查方向:
switch (orientation) {
case UIInterfaceOrientationPortrait:
// Do something.
break;
case UIInterfaceOrientationPortraitUpsideDown:
// Do something.
break;
case UIInterfaceOrientationLandscapeLeft:
// Do something.
break;
case UIInterfaceOrientationLandscapeRight:
// Do something.
break;
}
编辑:要让您的应用程序自动旋转,您可以执行以下操作:
- (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;
}
答案 1 :(得分:2)
UIInterfaceOrientation orientation = [UIDevice currentDevice].orientation;