菜鸟教程小白 发表于 2022-12-11 18:18:54

ios - 我希望一个 Viewcontroller 仅以横向模式显示


                                            <p><p>我目前正在开发一个只能锁定为纵向模式的移动应用程序。因为我可以在我的项目设置中执行此操作,所以这不是问题,但我希望一个 Viewcontroller 仅以横向模式显示。 </p>

<p>我尝试在项目设置中禁用纵向模式,并将这段代码添加到我的横向 ViewController (以及调用它的 Controller ,但具有纵向):</p>

<pre><code>let value =UIInterfaceOrientation.landscapeLeft.rawValue
UIDevice.current.setValue(value, forKey: &#34;orientation&#34;)
UIViewController.attemptRotationToDeviceOrientation()
</code></pre>

<p>我现在面临的问题是,这个解决方案不是最优的。用户仍然能够旋转他的设备。我该如何解决这个问题?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>尝试锁定自动旋转</p>

<pre><code> override var shouldAutorotate : Bool {
    // Lock autorotate
    return false
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 我希望一个 Viewcontroller 仅以横向模式显示,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/41085204/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/41085204/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 我希望一个 Viewcontroller 仅以横向模式显示