![](/img/trans.png)
[英]UINavigationController setViewControllers autorotation issue
[英]UiNavigationController Autorotation not Working on Device?
为什么UINavigationController AutoRotation无法在设备上运行? 如何为UinavigationController设置自动旋转属性?
**BusinessCardAppDelegate.m**
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self.window makeKeyAndVisible];
RootView *rView=[[RootView alloc]initWithNibName:@"RootView" bundle:nil];
self.naviGationController =[[[UINavigationController alloc]initWithRootViewController:rView]autorelease];
[self.window addSubview:naviGationController.view];
return YES;
}
**RootView.m**
- (void)viewDidLoad
{
[super viewDidLoad];
self.title =@"BusinessCard";
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationFunction:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
-(void)orientationFunction:(NSNotification*)notification
{
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
switch (orientation)
{
case UIDeviceOrientationPortrait:
/* AlertView Show*/
break;
case UIDeviceOrientationPortraitUpsideDown:
/* AlertView Show*/
break;
case UIDeviceOrientationLandscapeLeft:
/* AlertView Show*/
break;
case UIDeviceOrientationLandscapeRight:
/* AlertView Show*/
break;
default:
break;
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
为什么这在设备上不起作用,但在模拟器中可以正常工作? 我不明白为什么这行不通? 提前致谢。
[[UIDevice currentDevice] orientation]
返回UIDeviceOrientation,而不是UIInterfaceOrientation。
如果要获取当前的界面方向,可以使用以下方法:
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
要么
UIInterfaceOrientation orientation = self.interfaceOrientation; // into UIViewController
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.