简体   繁体   English

如何在Swift 2中的特定方向上正确锁定ViewController?

[英]How do I properly lock my viewController in a specific orientation in swift 2?

I want to lock my viewController in portrait mode, i tried using the following lines, but they haven't worked: 我想将我的viewController锁定为纵向模式,我尝试使用以下几行,但是它们没有用:

override func shouldAutorotate() -> Bool {
        return false
    }

    override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        let orientation: UIInterfaceOrientationMask = [UIInterfaceOrientationMask.Portrait, UIInterfaceOrientationMask.PortraitUpsideDown]

        return orientation
    }

how do I properly achieve this? 我如何正确地做到这一点?

If you are trying to just have that one orientation for your app, follow these steps. 如果您只是尝试为应用提供一种方向,请按照以下步骤操作。

  1. Go to the left-most pane of Xcode (it's called the Project Navigator) and select the topmost icon that is named the name of your app. 转到Xcode的最左侧窗格(称为Project Navigator),然后选择名为应用程序名称的最顶部图标。
  2. The editor section will change to your app's settings and configurations. 编辑器部分将更改为您应用的设置和配置。 Select "General" 选择“常规”
  3. Scroll down to near the bottom to "Deployment Info". 向下滚动到底部附近的“部署信息”。 Under that section is the "Device Orientation" section. 在该部分下面是“设备方向”部分。
  4. Click the required orientations 点击所需的方向

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

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