How to force screen orientation at some ViewController on iPad Air2 iOS9.2?

At iOS8 i used

- (BOOL)shouldAutorotate
{
    return NO;
}

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationPortrait;
}

but not working at iOS9 iPad Air2, Also, I find another solution but not working either, override the function below in custom UINavigationController:

-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return [self.viewControllers.lastObject supportedInterfaceOrientations];
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];
}
-(BOOL)shouldAutorotate{
    return self.visibleViewController.shouldAutorotate;
}

Can someone help me? Thanks!

Answers


You certainly had defined the allowed orientations in info.plist which overrides anything you do anywhere else throughout the project.

To correct the issue you can removed the entries from info.plist and defined them in the project settings.


try this in viewDidAppear:

  NSNumber *orientationValue = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue: orientationValue forKey:@"orientation"];

it can be flicker in this answer. if you don't want flicker, try this option it will work:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([self.window.rootViewController.presentedViewController isKindOfClass: [SecondViewController class]])
{
    SecondViewController *secondController = (SecondViewController *) self.window.rootViewController.presentedViewController;
            return UIInterfaceOrientationMaskLandscapeRight;
}
return UIInterfaceOrientationMaskPortrait;

}

Need Your Help

Schema modelling with functions

function functional-programming schema data-modeling first-class-functions

I am looking for a schema language that allows definition of functions. I thought of http://json-schema.org/ at first, but that format is data-only. My knowledge from XSD is the same.

force getting gps location

java android gps locationmanager

I'm searching about some code to force my app to get GPS location quickly ASAP