Why is UINavigationController AutoRotation not working on the Device? How can I set auto Rotation property for 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;
}
Why this is not working on device, but working fine in simulator? I didn't understand why this is not working? thanks in advance.
[[UIDevice currentDevice] orientation]
returns UIDeviceOrientation, not UIInterfaceOrientation.
If you want to get your current interface orientation you can use follow:
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
or
UIInterfaceOrientation orientation = self.interfaceOrientation; // into UIViewController
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.