In my universal app i need to handle different orientation for iphone and ipad. For ipad i need to allow landscape orientation and for iphone portrait alone. I have returned below code at first
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
is working fine in IOS 5 But in IOS 6 autorotate method is not at all fired. After that i have changed the method to,
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationMaskPortrait;
}
even this methods are not at all fired in IOS 6.
My plist setting is
i need to handle both orientation [iPhone-portrait,iPad-landscape] for both IOS 5 and IOS 6. Please guide me to fix this issue.
Is your rootviewcontroller a UINavigation controller or UITabbarcontroller?? If so these methods wont work if you are calling these methods in your view controller.
So create an objective C category on these container view controllers and add to your project.
@implementation UINavigationController (autorotate)
-(NSUInteger)supportedInterfaceOrientations
{
//make the check for iphone/ipad here
if(IPHONE)
{
return UIInterfaceOrientationMaskPortrait;
}
else
{
return UIInterfaceOrientationMaskLandscape;
}
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotate
{
return NO;
}
add this method to your app delegate its 100% working
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window // iOS 6 autorotation fix
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return UIInterfaceOrientationPortraitUpsideDown;
}
else
return UIInterfaceOrientationMaskAll;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With