0

Am using iOS6 device xcode 4.5 & mountain lion mac. And in my app am starting in portrait mode(3 screens). But 4th screen should be in landscape and should support landscape left & landscape right.

Most of the explanations are shown how to rotate.

in appddelegate am using

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
      UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
navigationController.navigationBar.tintColor = [UIColor blackColor];


// Set RootViewController to window
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
    // warning: addSubView doesn't work on iOS6
     [self.window addSubview: navigationController.view];
}   
else
{
     // use this mehod on ios6
     [self.window setRootViewController:navigationController];
}

}
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if(self.shouldRotate ) //shouldRotate is my flag
    {
         self.shouldRotate = NO;
         return (UIInterfaceOrientationMaskLandscapeRight);
    }
    return (UIInterfaceOrientationMaskPortrait);
}

and in my view controller which should be landscape and am using

 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
     AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
         appDelegate.shouldRotate = YES;
        // Custom initialization
    }
     return self;
 }



- (BOOL)shouldAutorotate
{
     return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
      return UIInterfaceOrientationMaskLandscape;
}

In my viewcontrollers which are potrait are working correctly in which am using

- (BOOL)shouldAutorotate
{
     return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
      return UIInterfaceOrientationMaskPortrait;
}

can any one suggest to do this

Thanks in advance

Kalyan Ram
  • 35
  • 7
  • The `[self.window setRootViewController:navigationController]` should be calles on iOS 4 and higher so just remove the check for iOS 6 and alway use the `self.window.rootViewController`property. – rckoenes Dec 06 '12 at 13:34
  • Just to put in my two cents, an app that supports landscape should support landscape through the entire app. You shouldn't be forcing your users to rotate their device in the middle of the workflow. – Ryan Poolos Dec 06 '12 at 13:34
  • self.window.rootViewController = navigationController; by using this one also not loading view in landscape – Kalyan Ram Dec 06 '12 at 13:37
  • hi Ryan Poolos but my app should support view in only one screen in landscape remaining are in portrait. – Kalyan Ram Dec 06 '12 at 13:39

2 Answers2

0

This is working for me I removed NavigationController and changed as follows

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        self.viewController = [[PlashViewController alloc] initWithNibName:@"PlashViewController" bundle:nil];
    }
    self.window.rootViewController = self.viewController;
   [self.window makeKeyAndVisible];
   return YES;
}

im my app am placed this methods in my view controllers as follows and in plist and target i specified three orientations like portrait , landscapeleft and landscaperight to show view in portrait

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

to show view in landscape

 - (BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
   return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
Kalyan Ram
  • 35
  • 7
0

I found that only the rootviewcontroller handles these things in iOs 6. Check out my answer here: https://stackoverflow.com/a/13033443/580173

Community
  • 1
  • 1
ejazz
  • 2,458
  • 1
  • 19
  • 29