0
votes

I am working on iOS 6 application, I have handled the UIview rotation using following methods...

-(NSUInteger)supportedInterfaceOrientations

{
    return UIInterfaceOrientationMaskPortrait;
}


- (BOOL) shouldAutorotate {
    return YES;
}

Everything is working fine, problem is initial view loading is decided based on device orientation, for e.g.: if I keep my device in landscape mode even though I have returned as forcibly portrait in supportedInterfaceOrientations view is showing in landscape only, once device is rotated to portrait after that it is not going to landscape mode, all working fine. Is it possible to load a View at certain mode irrespective of the device orientation?

I have googled and nothing worked.

NOTE: I am using navigation controller. And I have added category for UINavigationController.

// Custom categoy to handle orientation in IOS6

@implementation UINavigationController (Rotation_IOS6)

-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end

thanks

1

1 Answers

0
votes

Use this method:

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationMaskPortrait;
}

Add this method along with category for UINavigationController in appDelegate.

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
  UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
  //check for which controller u need these methods
  if([navigationController.visibleViewController isKindOfClass:[yourViewController class]]) //provide specific view controller where u want protrait
  {
    [navigationController shouldAutorotate];
    [navigationController supportedInterfaceOrientations];
    [navigationController preferredInterfaceOrientationForPresentation];
  }
  return UIInterfaceOrientationMaskAll;
}

Note : remove from all viewController if u have added category for UINavigationController. It should be only in appDelegate.