简体   繁体   English

如何启用或禁用特定 ViewController 的横向模式?

[英]How to enable or disable landscape mode for specific ViewControllers?

I have enabled landscape left and right modes in my Xcode.我在 Xcode 中启用了横向左右模式。

How to enable or disable landscape mode for specific ViewControllers?如何启用或禁用特定 ViewController 的横向模式?

For some VC's I required landscape and for some VC's I required only portrait mode.对于一些 VC,我需要横向模式,而对于一些 VC,我只需要纵向模式。

How to achieve it programatically in Objective C?如何在目标 C 中以编程方式实现它?

在此处输入图像描述

In your view controller, override the supportedInterfaceOrientations property在您看来 controller,覆盖supportedInterfaceOrientations属性

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return .landscape
}

You only need to make sure that you don't return anything that conflicts with the "Device Orientation" settings, otherwise the app will crash.您只需要确保不返回与“设备方向”设置冲突的任何内容,否则应用程序将崩溃。

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

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