Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to handle orientation in iOS 6?

I am using

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

delegate to change the frame of my view based on the orientation type

i.e.,

if(UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
    self.view.frame=CGRectMake(0,0,500,300);
}
else
{
    self.view.frame=CGRectMake(0,0,300,400);
}

How to handle the same situation in iOS 6 as

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

has been deprecated in iOS6.

I am using the following delegate to set all the orientations.

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationAllMask;
}

But,

-(BOOL)shouldAutoRotate
{
    return YES;

}

is not getting invoked. How to handle this situation?

enter image description here

like image 862
Bharath Avatar asked Sep 20 '12 19:09

Bharath


3 Answers

In the AppDelegate, I have added the ViewController Object to window as

[self.window addSubView:viewControllerObj]

The problem was with the above line. Orientation will work properly with the above line in iOS 5 but in iOS, for orientation to work properly, change the above line with

[self.window setRootViewController:viewControllerObj]

Then the app rotates when orientation changes.

like image 167
Bharath Avatar answered Oct 20 '22 20:10

Bharath


Make sure the settings in the project and target allow for the orientations for each device type.

Also, the code you have in shouldAutorotateToInterfaceOrientation: you can put in viewDidLayoutSubviews.

like image 23
Léo Natan Avatar answered Oct 20 '22 20:10

Léo Natan


Remember that in iOS 6 the handling of the rotation is take care in parents view. Less responsability to childs viewcontrollers. But more annoying for us that code everything without Interface builder.

like image 1
lagos Avatar answered Oct 20 '22 19:10

lagos