1

I have updated my Xcode to 4.5 , I have implemented the orientation methods as below

  -(BOOL)shouldAutorotate{

    return YES;

  }

-(NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskAll;
}

I am setting the frame sizes of buttons ,labels,images in willRotateToInterfaceOrientation method

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{


  if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait )||
        ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown ))
  {

    // set frame sizes for portait

   }

  else if(( [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft )||
            ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight ))

  {

    // set frame sizes for landscape

   }

}

but sometimes this method is not getting called when rotating the simulator and sometimes the simulator is not detecting orientation when navigating from another viewController . I have checked info.plist file - it is fine.

Brad Werth
  • 17,411
  • 10
  • 63
  • 88
Asif Iqbal
  • 11
  • 1
  • 2
  • -(BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation not -(BOOL)shouldAutorotate also did you set the view controller for the windows? – gjpc Sep 25 '12 at 15:28
  • check this out: http://stackoverflow.com/questions/12772749/support-different-orientation-for-only-one-view-ios-6 – JAHelia Jan 01 '13 at 06:39

2 Answers2

4

Apple does not call the shouldAutorotatetoInterfaceOrientation call in IOS 6.0 unless you tell the main window which view controller to send it to.

I got rotation to work in my app by setting the window.rootViewController to the top level view controller of my app in

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   ...
   window.rootViewController = topLevelViewController;
   ...
}

The iPhone version of my app only supports the two portrait orientations, so my top iPhone view controller required a new method:

- (NSUInteger)supportedInterfaceOrientations 
{
  return  UIInterfaceOrientationMaskPortrait |  
          UIInterfaceOrientationMaskPortraitUpsideDown;
}

here is a discussion on Buzz Touch.

gjpc
  • 1,428
  • 14
  • 21
  • 1
    Thanks god, i searched for exactly this information for about one hour.....there are many informations which aren't working anymore. Shame on apple that they are not downwards compatible! – Felix K. Nov 07 '12 at 19:06
  • Excellent answer. As Felix mentions, there's a LOT of discussion about this issue, but many confusing answers. This first piece of code was the piece of the puzzle that allowed me to get this working with iOS 5 and iOS 6 – Buzzrick Jul 13 '13 at 10:22
0

Apple has deprecated shouldautorate method from ios6 use these methods instead

- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0);
- (NSUInteger)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0);
// Returns interface orientation masks.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation NS_AVAILABLE_IOS(6_0);
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Saad
  • 8,857
  • 2
  • 41
  • 51