简体   繁体   English

如何停止设备方向更改

[英]How to stop the device Orientation changing

I'm working on an app that is to be in portrait mode when it is launched. 我正在开发一个在启动时处于纵向模式的应用程序。 After that, I add an SDK for some purpose to my project. 在那之后,我将出于某种目的的SDK添加到我的项目中。 In the process of the integrating the SDK needs both Portrait and Landscape Right checked in the General pane. 在集成SDK的过程中,需要在“常规”窗格中同时选中“纵向”和“横向”。 So I set it as given in the SDK integration manual. 因此,我按照SDK集成手册中的说明进行了设置。

在此处输入图片说明

and after that when I run my project in a device and rotate it to right the app device orientation is changing. 之后,当我在设备中运行项目并将其向右旋转时,应用程序设备的方向就会改变。 How can I set the orientation is fixed without disturbing the SDK. 在不干扰SDK的情况下如何设置方向是固定的。

if you're having trouble to set orientation right after the app launches then you might need to stop orientation for each view controller or one of it's base navigation controller 如果在应用启动后无法立即设置方向,则可能需要停止每个视图控制器或其基本导航控制器之一的方向

Swift 3: 斯威夫特3:

class YourBaseNavigationController: UINavigationController {
override func viewDidLoad() {
    super.viewDidLoad()
    UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
}
override var shouldAutorotate: Bool {
    return false
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .portrait
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
    return .portrait
}}

Use YourBaseNavigationController as your navigation controller.Basically all view controller within this navigation controller will be force to support portrait mode only. 使用YourBaseNavigationController作为导航控制器。基本上,此导航控制器中的所有视图控制器都将仅支持纵向模式。

取消标记支票左横向和右横向

You need to disable orientation through code. 您需要通过代码禁用定向。

Add this code in your RootViewController: 在您的RootViewController中添加以下代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);//set 'return NO'; for stop orientation
}

Swift : 斯威夫特

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.Portrait
}

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

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