In iOS 6 shouldAutorotateToInterfaceOrientation
is not working but it work fine in iOS 5.0
or 5.1
.
What should i need to change in iOS 6
.
Here is my code
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if([[[SampleApplicationAppDelegate instance].callInfoDictionary valueForKey:IS_CHAT] isEqualToString:NO_RESPONSE])
{
int nAngle = 0;
BOOL bRet = NO;
switch (interfaceOrientation) {
case UIInterfaceOrientationPortrait:
nAngle = 90;
bRet = YES;
NSLog(@".......Preview = %f %f",_previewCamera.frame.size.width,_previewCamera.frame.size.height);
_previewCamera.transform = CGAffineTransformMakeRotation(M_PI*1.5);
NSLog(@"Preview = %f %f",_previewCamera.frame.size.width,_previewCamera.frame.size.height);
break;
case UIInterfaceOrientationPortraitUpsideDown:
nAngle = 270;
bRet = YES;
_previewCamera.transform = CGAffineTransformMakeRotation(M_PI_2);
break;
case UIInterfaceOrientationLandscapeLeft:
nAngle = 0;
bRet = YES;
//_previewCamera.transform = CGAffineTransformMakeRotation(M_PI*1.5);
break;
case UIInterfaceOrientationLandscapeRight:
nAngle = 180;
bRet = YES;
//_previewCamera.transform = CGAffineTransformMakeRotation(M_PI_2);
break;
default:
break;
}
return bRet;
}
if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
return YES;
return NO;
}
when i search for this orientation problem i found all this
but nothing work for me :( Please help .....
please try this one it will be helpful for you.
write code in you viewcontroller class
Then in appdelegate search this line [window addSubview:viewController.view] and replace this with window.rootViewController = viewController;
cheers it will work.its simple solution for ios 6
The way I fixed this problem was to replace the following line when my app starts in Delegate Class
with
After I made this change my app started to handle screen rotations
this worked for me
This is because Apple has deprecated shouldautorate method from ios6 use these methods instead
EDIT: This is happening because Apple has changed the way of managing the Orientation of
UIViewController
. In iOS6 orientation handles differently. In iOS6shouldAutorotateToInterfaceOrientation
method is deprecated. View controllers (such asUINavigationController
) do not consult their children to determine whether they should autorotate. By default, an app and a view controller’s supported interface orientations are set toUIInterfaceOrientationMaskAll
for the iPad idiom andUIInterfaceOrientationMaskAllButUpsideDown
for the iPhone idiom.If you want a specific view to be changed to the desired orientation you have to do some sort of subclass or category and override the autorotation methods to return the desired orientation.
Place this code in your root view controller. This will help the
UIViewController
to determine its orientation.Now you need to implement below methods (introduced in iOS6) in viewController for orientation
And put your code inside the below method. Whenever device orientation is changed this method will be called:
Edit: check your window, you need to add the controller on window as
rootViewController
rather thanaddSubview
like belowFor more information here's an article about iOS6.0 Beta 2 OTA.
I hope this was helpful.
I Solved this problem just use this