简体   繁体   中英

orientation not supporting in ios6 devices

i have an application build on xcode 4.2 , which supports only portrait orientation, it works fine with all devices except ios6 .. In Ios 6 devices it is showing both orientations .. I need only portrait orientation .. i am using navigation controller .. IN appdelegate::

- (BOOL)shouldAutorotate
{

      return ([[UIDevice currentDevice] orientation]==UIInterfaceOrientationPortrait);
}


- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
     return (UIInterfaceOrientationMaskPortrait);
}

in other viewControllers ::

- (BOOL)shouldAutorotate {
    return YES;
}

- (void)viewDidLayoutSubviews
{
    DisplayFunctionName;
    NSLog(@"orientation: %d",self.interfaceOrientation);
}

- (NSUInteger)supportedInterfaceOrientations
{
    if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
    {
        return (UIInterfaceOrientationMaskAll);
    }
    else
    {
        return (UIInterfaceOrientationMaskPortrait);
    }
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    DisplayFunctionName;
    NSLog(@"orientation: %d",interfaceOrientation);
      return (interfaceOrientation==UIInterfaceOrientationPortrait);

}

In IOS6 handling of Orientation is difficult is case when you want portrait orientation for some views and for some you want landscape orientation, but its very easy if you want only one orientation support for entire app. simple go to Supporting Files and then open the info.plist in your app and remove all other orientation except one that you want.. below are few screen shot which help you to fix your issue

在此输入图像描述

在此输入图像描述

after removing all other orientation your info.plist will be looks like below 在此输入图像描述

i hope it works for you.Thanks

iOS 6

shouldAutorotateToInterfaceOrientation : is deprecated and replaced by

shouldAutorotate

Check this : https://stackoverflow.com/a/14938444/305135

Try using these ,

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationPortrait;
}

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationPortrait;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM