首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在iPad Air2 iOS9.2上的某些ViewController上强制屏幕方向?

如何在iPad Air2 iOS9.2上的某些ViewController上强制屏幕方向?
EN

Stack Overflow用户
提问于 2016-01-15 21:46:00
回答 2查看 149关注 0票数 0

在iOS8,我使用

代码语言:javascript
复制
- (BOOL)shouldAutorotate
{
    return NO;
}

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationPortrait;
}

但不适用于iOS9 iPad Air2,而且,我找到了另一个解决方案,但也不起作用,在自定义UINavigationController中覆盖以下函数:

代码语言:javascript
复制
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return [self.viewControllers.lastObject supportedInterfaceOrientations];
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];
}
-(BOOL)shouldAutorotate{
    return self.visibleViewController.shouldAutorotate;
}

有人能帮我吗?谢谢!

EN

回答 2

Stack Overflow用户

发布于 2016-01-15 22:06:23

您当然已经在info.plist中定义了允许的方向,它覆盖了整个项目中您在其他任何地方所做的任何事情。

要解决此问题,您可以从info.plist中删除这些条目,并在项目设置中对其进行定义。

票数 1
EN

Stack Overflow用户

发布于 2016-01-15 22:02:01

在viewDidAppear中尝试:

代码语言:javascript
复制
  NSNumber *orientationValue = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue: orientationValue forKey:@"orientation"];

在这个答案中它可以是闪烁的。如果你不想要闪烁,试试这个选项,它会工作的:

代码语言:javascript
复制
- (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;

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34812483

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档