简体   繁体   English

iOS方向在特定屏幕上同时支持横向和纵向-并非所有屏幕

[英]iOS Orientation Support both Landscape and Portrait on specific screen - NOT ALL Screens

Comrades, 同志们

I just would like to know, how to enable Landscape Orientation only on Specific screens? 我只想知道,如何仅在特定屏幕上启用横向显示? As of now, I selected Landscape Left and Right options in General Settings and enabled in Supported interface orientations (iPhone) in plist file for the device Orientation, but that impacts all the screens. 到目前为止,我在“常规设置”中选择了“横向左和右”选项,并在plist文件的“支持的界面方向”(iPhone)中为设备“方向”启用了该功能,但这会影响所有屏幕。

I have nearly 80 screens in my application, I need to support both Portrait and Landscape about 5 screens, rest of the screens should be shown only in Portrait mode. 我的应用程序中有近80个屏幕,我需要同时支持纵向和横向5个屏幕,其余屏幕仅应在纵向模式下显示。

Any help is greatly appreciated! 任何帮助是极大的赞赏!

Thanks, Ramesh 谢谢,拉梅什

In General Settings (which just adjusts your plist), you need to select all possible supported orientations. 在常规设置(仅调整您的plist)中,您需要选择所有可能的受支持的方向。 Then, you need to limit them in your specific view controller. 然后,您需要在特定的视图控制器中限制它们。 If you're using a NavBar or TabBar controller, you need add your limitation there. 如果您使用的是NavBar或TabBar控制器,则需要在其中添加限制。

From the UIViewController docs: 从UIViewController文档:

In iOS 6 and later, your app supports the interface orientations defined in your app's Info.plist file. 在iOS 6和更高版本中,您的应用程序支持在应用程序的Info.plist文件中定义的界面方向。 A view controller can override the supportedInterfaceOrientations method to limit the list of supported orientations. 视图控制器可以重写supportedInterfaceOrientations方法以限制支持的方向列表。 Typically, the system calls this method only on the root view controller of the window or a view controller presented to fill the entire screen; 通常,系统仅在窗口的根视图控制器或显示为填充整个屏幕的视图控制器上调用此方法。 child view controllers use the portion of the window provided for them by their parent view controller and no longer participate directly in decisions about what rotations are supported. 子视图控制器使用其父视图控制器为其提供的窗口部分,而不再直接参与有关支持哪些旋转的决策。 The intersection of the app's orientation mask and the view controller's orientation mask is used to determine which orientations a view controller can be rotated into. 应用程序的方向蒙版和视图控制器的方向蒙版的交集用于确定视图控制器可以旋转到的方向。

To make this simpler, I created a category on UINavigationController that looks at the top-most view controller to determine it's rotation abilities. 为简化起见,我在UINavigationController上创建了一个类别,该类别查看最顶部的视图控制器以确定其旋转能力。 That way, in my specific view controllers that needed rotating, I could override those same methods and add landscape support. 这样,在需要旋转的特定视图控制器中,我可以覆盖这些相同的方法并添加横向支持。

@implementation UINavigationController (AutoRotation)

- (NSUInteger)supportedInterfaceOrientations
{
    return [self.topViewController supportedInterfaceOrientations];
}

- (BOOL)shouldAutorotate
{
    return [self.topViewController shouldAutorotate];
}

@end

Are your screens inside a UINavigationController ? 屏幕是否在UINavigationController If so, I've noticed not all viewControllers can decide what orientations they support. 如果是这样,我注意到并不是所有的viewController都可以决定它们支持的方向。

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

相关问题 IOS Tableview支持所有屏幕和横向屏幕 - IOS Tableview support all screens and Landscape screen 如何在IOS的xamarin.forms中将单个ContentPage的方向从纵向更改为全部(横向/纵向)。 - How to change orientation from Portrait to All (Landscape/Portrait both) for the single ContentPage in xamarin.forms for IOS? 横向定向屏幕中的ios横向屏幕结果 - ios landscape-orientation screen in portrait orientation results iOS 中纵向和横向的屏幕方向(Objective-C) - Screen Orientation for Portrait and Landscape Orientation in iOS (Objective-C) 如何允许特定的视图控制器同时支持横向和纵向 - How to allow a particular view controller to support for both landscape and portrait orientation 如何在iOS应用程序中同时管理横向和纵向方向? - How to manage both landscape & portrait orientation in iOS application? 支持UIDocumentInteractionController的横向和纵向方向 - Support landscape and portrait orientation for UIDocumentInteractionController iOS:纵向/横向网格 - iOS: grid in portrait / landscape orientation iOS ViewController仅支持纵向,但弹出窗口支持所有方向 - iOS ViewController only support portrait but popup support all orientation 在应用程序iPhone中管理方向风景和人像 - Manage orientation landscape and portrait both in a app iPhone
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM