菜鸟教程小白 发表于 2022-12-11 22:39:50

ios - 锁定方向在 ipad ios 8 swift xcode 6.2 上不起作用


                                            <p><p>我像这样将应用程序方向从一般应用程序设置锁定为纵向</p>

<p> <img src="/image/ScAaR.png" alt="portrait"/> </p>

<p>但是当我在 ipad 上运行我的应用程序时,它还是会旋转!?</p>

<p>那么我应该在哪里锁定方向?</p>

<p>为什么苹果在设置中添加了这个功能,而它却不起作用!?</p>

<p><strong>更新:</strong></p>

<p>我也尝试将此 viewController 实现为所有 viewController 的通用。</p>

<pre><code>import Foundation
import UIKit

class GeneralViewController: UIViewController {

    override func viewDidAppear(animated: Bool) {
      super.viewDidAppear(animated)
      let value = UIInterfaceOrientation.Portrait.rawValue
      UIDevice.currentDevice().setValue(value, forKey: &#34;orientation&#34;)
    }

    override func supportedInterfaceOrientations() -&gt; Int {
      return Int(UIInterfaceOrientationMask.Portrait.rawValue)
    }


    override func preferredInterfaceOrientationForPresentation() -&gt; UIInterfaceOrientation {
      return UIInterfaceOrientation.Portrait
    }

    override func shouldAutorotate() -&gt; Bool {
      return false
    }
}
</code></pre>

<p>这张图片取 self 应用的主导航 Controller 。</p>

<p> <img src="/image/zbUMS.png" alt="Pic of answer 1"/> </p>

<p>还是不行!</p>

<p>这东西到底是怎么工作的?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您不需要额外的代码,我正在开发 Xcode 7.0.1,我注意到当我将屏幕方向锁定为仅纵向时,它仅锁定在 iPhone 中,也锁定在 iPad 中,您需要选择iPad从设备(而不是通用)并检查纵向并取消选中其他,然后再次将设备返回通用,因为我发现通用仅反射(reflect)在iPhone中,它可能是Xcode中的某种错误。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 锁定方向在 ipad ios 8 swift xcode 6.2 上不起作用,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/55490424/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/55490424/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 锁定方向在 ipad ios 8 swift xcode 6.2 上不起作用