简体   繁体   English

在iPad的UIPageViewController中强制使用肖像模式

[英]Forcing Portrait Mode in a UIPageViewController on iPad

I have an iPad app which supports Portrait and Landscape in the entire app. 我有一个iPad应用程序,该应用程序在整个应用程序中都支持纵向和横向。 This is an iOS 7 and iOS 8 version of an app. 这是应用程序的iOS 7和iOS 8版本。

The app is a UITableViewController with multiple segues to a different set of UIViewControllers . 该应用程序是一个UITableViewController具有对一组不同的UIViewControllers多个选择。 I have one option in the app to show the Tutorial again and I have created the images in a Portrait mode only orientation because it just wouldn't make too much sense (or look good in Landscape). 我在应用程序中有一个选项可以再次显示该教程,并且我已经以“人像”模式创建了图像,因为这不会太有意义(或者在“风景”中看起来不错)。

With this in mind, the tutorial is in the form of images loaded into a UIPageViewController . 考虑到这一点,本教程采用将图像加载到UIPageViewController中的形式。 The images are loaded in the viewDidLoad and the buttons and layout work really well. 图像被加载到viewDidLoad ,按钮和布局工作得很好。

Issue I want to restrict the UIPageViewController to be in a Portrait orientation only. 问题我想将UIPageViewController限制为仅纵向。

Currently, I have: 目前,我有:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    [[UIDevice currentDevice] setValue:
     [NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
                                forKey:@"orientation"];

}

That works to some extent. 这在一定程度上起作用。 If the device is in Landscape mode and the tutorial is invoked, it rotates it to Portrait. 如果设备处于横向模式并且调用了教程,则会将其旋转为纵向。

However, if the device is in Portrait and I rotate it to Landscape after invoking the Tutorial, the tutorial then rotates. 但是,如果设备处于“纵向”模式,并且在调用“教程”后将其旋转为“风景”,则教程将旋转。

How exactly do I prevent this view from rotating in my custom UIPageViewController class, so that it never rotates to Landscape whether it's at the start, middle, or end of the tutorial. 我如何确切地防止该视图在我的自定义UIPageViewController类中旋转,以使其无论在教程的开始,中间还是结束时都不会旋转为Landscape。

Any guidance on this would really be appreciated. 对此的任何指导将不胜感激。

Take a look at UIViewController docs for Orientation support, specifically shouldAutorotate: and supportedInterfaceOrientations - https://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIViewController_Class/index.html#//apple_ref/occ/instm/UIViewController/supportedInterfaceOrientations 看看UIViewController文档中的Orientation支持,特别是shouldAutorotate:supportedInterfaceOrientations - https shouldAutorotate: //developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIViewController_Class/index.html#//apple_ref/occ/instm/的UIViewController / supportedInterfaceOrientations

My first guess would be you would want to set the value like you're doing now, and then override shouldAutorotate in your custom UIPageViewController subclass and return NO. 我的第一个猜想是你想设置的值像你现在这样,然后重写shouldAutorotate在您的自定义UIPageViewController子类,返回NO。

However, be aware you could get hit in the review process for HIG compliance, because your app claims to support all orientations, but parts of it don't. 但是,请注意,您可能会在审核过程中受到HIG合规性的影响,因为您的应用声称支持所有方向,但部分内容不支持。 Obviously this is totally up to the reviewer and whether or not they catch it as plenty of other apps do this. 显然,这完全取决于审阅者,以及是否由其他许多应用程序来做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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