在iOS8,我使用
- (BOOL)shouldAutorotate
{
return NO;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortrait;
}但不适用于iOS9 iPad Air2,而且,我找到了另一个解决方案,但也不起作用,在自定义UINavigationController中覆盖以下函数:
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return [self.viewControllers.lastObject supportedInterfaceOrientations];
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];
}
-(BOOL)shouldAutorotate{
return self.visibleViewController.shouldAutorotate;
}有人能帮我吗?谢谢!
发布于 2016-01-15 22:06:23
您当然已经在info.plist中定义了允许的方向,它覆盖了整个项目中您在其他任何地方所做的任何事情。
要解决此问题,您可以从info.plist中删除这些条目,并在项目设置中对其进行定义。

发布于 2016-01-15 22:02:01
在viewDidAppear中尝试:
NSNumber *orientationValue = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue: orientationValue forKey:@"orientation"];在这个答案中它可以是闪烁的。如果你不想要闪烁,试试这个选项,它会工作的:
- (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;
}https://stackoverflow.com/questions/34812483
复制相似问题